Oil prices gained Wednesday after U.S. government inventory data showed a decline in crude-oil supplies as refineries processed more oil than expected last week.

Crude-oil stockpiles decreased by 4.5 million barrels to 362.5 million barrels, the U.S. Energy Information Administration said Wednesday. Analysts had expected stocks to fall by 900,000 barrels on the week, according to a Wall Street Journal survey.

Light, sweet oil for September delivery settled up $1.59, or 1.7%, at $96.07 a barrel on the New York Mercantile Exchange. The September contract expired at settlement. The more-actively traded October contract rose 59 cents, or 0.5%, to $93.45 a barrel.

Brent prices rose 72 cents, or 0.7%, to $102.28 a barrel on ICE Futures Europe.

Oil prices "appeared to scoop up support off of a larger-than-expected U.S. crude stock draw," said energy-advisory firm Ritterbusch & Associates in a note.

Refining capacity utilization rose by 1.8 percentage points to 93.4% of capacity. Analysts had expected the operating rate to fall by 0.3 percentage point in the week.

"That was unexpected, the amount of increased utilization," said Andy Lipow, president of Lipow Oil Associates in Houston. "Across the country, refiners are running at high utilization rates."

Oil stockpiles are at their lowest since February, after hitting record highs in April. Supplies typically fall in the summer and build in the fall when refiners shut down units for seasonal maintenance.

"Outages this October are expected to average over 830 (thousand barrels a day), which dwarfs the 425 (thousand barrels a day) that we typically see for that time of year," said Mike Tran, analyst at CIBC World Markets, in a note.

Gasoline stockpiles rose by 585,000 barrels to 213.3 million barrels. Analysts had predicted a 1.3 million-barrel drop.

Front-month September reformulated gasoline blendstock, or RBOB, settled up 1.72 cents, or 0.6%, at $2.7126 a gallon.

Distillate stocks, which include heating oil and diesel fuel, fell by 960,000 barrels to 121.5 million barrels, compared with analysts' forecast of a decline of 700,000 barrels.

September diesel edged up 0.87 cent, or 0.3%, to $2.8258 a gallon.

"What is concerning is over the last several months we haven't built significant quantities of diesel fuel" ahead of the winter season, when demand for diesel and heating oil increases, Mr. Lipow said. "We certainly could see prices increase."

The September contract settled $2.62 a barrel above the October contract, an unusually large price gap, indicating that traders were willing to pay a premium to ensure immediate delivery of oil. Supplies in Cushing, Okla., are near six-year lows, though storage levels there grew by 1.8 million barrels last week.

The shrinking supplies at Cushing have buoyed oil prices in recent months, as a new pipeline shipped millions of barrels from Cushing to the Gulf Coast and sparked some worries that not enough oil would be available in Cushing for traders taking physical delivery of the Nymex oil contract.

Last week's rise in Cushing supplies is partly attributable to a refinery closure in Kansas, analysts said.

Genscape Inc., which tracks oil supplies at Cushing, said in a blog post Wednesday that it had detected some restart activity at the Kansas refinery and increased pipeline outflows out of Cushing, indicating that supplies could fall again later this month.