Oil futures topped $45 a barrel on Wednesday, posting its best gain in about three months as futures rebounded from a two-month low.

U.S. government data revealed a weekly increase in crude supplies that was smaller than some forecasts, and distillate stockpiles fell more than expected.

Read: Why oil is rallying despite 5 weeks of rising supplies

December West Texas Intermediate crude CLZ25, -0.75% climbed $2.74, or 6.3%, to settle at $45.94 a barrel on the New York Mercantile Exchange. That was the highest settlement since Oct. 20, and its best point and percentage gain since Aug. 31. December Brent crude UK:LCOZ5 rose $2.24, or 4.8%, to $49.05 a barrel on London’s ICE Futures exchange.

The U.S. Energy Information Administration on Wednesday reported an increase of 3.4 million barrels in crude supplies for the week ended Oct. 23. Analysts polled by Platts expected supplies to be up by 1.6 million barrels, while those surveyed by The Wall Street Journal looked for a 3.7 million-barrel rise. The American Petroleum Institute Tuesday said inventories rose 4.1 million barrels.

A drop in crude imports “helped to offset the rebound in refinery utilization to yield a solid build for oil inventories, [which are] now up to 480 million barrels—up 26 million barrels in the last five weeks,” said Matt Smith, a commodity analyst at ClipperData.

“The demand side of the equation is encouraging from the products, while inventories across the board remain robust to offset this supportive influence,” he said.

Gasoline supplies fell by 1.1 million barrels, while distillate stockpiles declined by three million barrels last week, according to the EIA.

On Nymex, November gasoline US:RBX5 rose 6.3 cents, or 4.9%, to $1.35 a gallon, while November heating oil US:HOX5 gained 6 cents, or 4.2%, to $1.484 a gallon.

November natural gas US:NGX15 shed 5.9 cents, or 2.8%, to end at $2.033 per million British thermal units on its expiration day. The December contract US:NGZ15, the new front month, settled at $2.298.

U.S. crude oil inventories remain near levels not seen for this time of year in at least the last 80 years, according to the EIA.

Tariq Zahir, a managing member at Tyche Capital Advisors, said he still sees fundamental weakness in the crude-oil market linked to the levels of supply. “It didn’t surprise me to see [oil prices] higher here,” he said. “But there’s nothing fundamental that suggests to me that we should be headed back to the $50 [a barrel] level,” he said.

The increase in U.S. stockpiles adds to the global oversupply that has battered prices since last year. Reluctance by major oil producers such as Russia and the Organization of the Petroleum Exporting Countries to trim output has kept prices at levels last seen during the financial crisis.

Persian Gulf countries are opposed to Venezuela’s proposal to hold an oil-price summit with heads of state from OPEC and non-OPEC members, according to The Wall Street Journal, which cited officials familiar with the matter.

Expectations the U.S. Federal Reserve wouldn’t announce at interest-rate hike at its meeting Wednesday had put pressure on the U.S. dollar DXY, +0.15% , which helped provide support for dollar-denominated commodities, including oil.

Shortly before oil prices settled, the Fed said it left interest rates unchanged, but also kept the door open for a potential hike at the December meeting. That fueled a rally in the dollar and caused a last-minute push away from the day’s highs for oil.

—Mark DeCambre contributed to this article