U.S. oil ended at a two-week high on Wednesday after government data showed a larger-than-expected drop in inventories while a rise in Brent was restrained by expectations Iranian and Libyan crude supplies may increase.

With the front-month contracts for Brent and U.S. crude set to expire in the coming days, traders bought contracts to cover positions, driving prices higher.

The biggest market driver was a U.S. government report showing crude inventories fell significantly more than expected. Ultra low-sulfur diesel futures (ULSD) rose to a more than one-week high on a surprise draw, while gasoline inventories rose as arctic-like weather last week kept drivers off the road.

"This is a weather related report," said Mark Waggoner, president of Excel Futures in Bend, Oregon. "People just weren't driving - they were sitting at home.

U.S. oil extended gains by $2.01 to a session high of $94.60, then settled $1.58, or 1.7 percent, higher at $94.17 a barrel, its highest settlement since Jan. 2. The February contract expires on Tuesday following a long U.S. holiday weekend.

February Brent crude rose $1.16 to a session high of $107.55, before settling up 74 cents at $107.13 a barrel. The contract expires on Thursday.

Analysts said the rebound in crude oil was overdue. "I think the market was oversold" when it was down near $91, said Rich Ilczyscyn, chief market strategist and founder of iitrader.com in Chicago.

Buoyant equities also supported oil. The S&P 500 reached an all-time high Wednesday, a reassuring signal to traders that the economy is showing signs of stability even as the U.S. Federal Reserve tapers its massive stimulus program.

Brent's premium to U.S. crude oil narrowed as the start date of the southern leg of TransCanada's Keystone pipeline nears. The pipeline is expected to begin taking crude oil from Cushing, Oklahoma, to the Gulf Coast starting Jan. 22. The spread <CL-LCO1=R> narrowed by 84 cents to settle at $12.96, the smallest gap in nearly two weeks.

"You're going to see it narrowing in the long haul," Waggoner said. "I would not doubt if the spread narrows to $2-$3 before summertime."

U.S. crude oil stocks fell 7.7 million barrels, compared with estimates of 600,000 barrels. Distillate supplies fell as the market expected an increase and gasoline inventories ballooned, U.S. Energy Information Administration data showed.

ULSD futures ended 1.5 percent higher at $2.9796 a gallon. U.S. gasoline futures settled virtually flat at $2.6264 a gallon.

LIBYA, IRAN WEIGH

The resumption of oil production at Libya's El Sharara field capped a rise in Brent, although the main issue is still when the blockade at Libya's eastern oil ports will end.

Iranian oil exports could also rise by some 500,000 barrels per day (bpd) through a oil-for-goods deal being negotiated with Russia, according to Russian and Iranian sources.

Major world powers and Iran have continued to move ahead on an interim deal that eases some sanctions on Tehran in exchange for curbs on its nuclear program.

The preliminary accord between Iran and a group of world powers goes into effect on Jan. 20. Under the deal, Iran's oil exports are to hold at current levels of about 1 million barrels per day.

Brent drew support from news of loading delays on North Sea Forties oil cargoes. The Forties crude blend is the most important of the North Sea crudes underpinning Brent crude.

The delay of those cargoes, coupled with a large draw from U.S. Gulf Coast inventories, helped bump cash crude differentials to nine-month highs. 

(By Elizabeth Dilts; Additional reporting by Jeanine Prezioso, Sabina Zawadzki and Selam Gebrekidan in New York, Julia Payne in London and Florence Tan; Editing by William Hardy, Jason Neely, Andrew Hay and Steve Orlofsky)