US crude settles up $2.49, or 5.2%, at $50.09 a barrel

Oil demand is 'phenomenal': Analyst
Oil demand is 'phenomenal': Analyst

Oil rallied on Wednesday for the first time in four days after weekly U.S. stock builds turned out to be less than some feared, and negotiators missed a deadline on Iranian nuclear talks that might bring more supply to the market.

U.S. oil futures closed up $2.49, or 5.2 percent, at $50.09 a barrel after government data showed crude inventories in the United States rose 4.8 million barrels to 471.4 million in the week to March 27, hitting record highs for a 12th straight week.

While analysts in a Reuters poll had expected a 4.2-million-barrel build on average last week, some feared a bigger rise after industry group the American Petroleum Institute suggested as much as 5.2 million barrels in a Tuesday report.

Read MoreIran's nuclear deal and how it could affect oil

Domestic crude production also fell 0.4 percent to 9.4 million barrels per day, the first weekly decline since the end of January.

U.S. gasoline demand has also risen over the past four weeks, up 2 percent from the same period a year ago, government data showed.

"Clearly, there is a (gasoline) demand response underway by consumers to the low retail price," said John Kilduff, partner at New York energy hedge fund Again Capital.

Iran deal: Congress eyes Netanyahu
Iran deal: Congress eyes Netanyahu

Brent crude for May delivery was up $2 at $57 a barrel.

Iran and six world powers extended talks in Lausanne, Switzerland, past a Tuesday deadline on reaching a preliminary accord for Tehran's nuclear program that could lift sanctions imposed on the OPEC member's oil exports.

Read MoreWhy does Carl Icahn keep buying up Chesapeake Energy?

"A lot of people were expecting the deal to be done overnight and Iran to be pumping a million barrels tomorrow. That's not going to be the case," said Amrita Sen, chief oil analyst at Energy Aspects.

"Everybody's been lowering expectations and I think that's feeding into prices," she said.

Iran produces about 2.8 million bpd, according to a Reuters survey, although Western sanctions limit exports to 1 million bpd. It keeps about 30 million barrels on its fleet of tankers ready to be sold, if possible.