Oil jumped as much as 5 percent on Wednesday, snapping a three-session losing streak, as U.S. crude output fell for the first time in two months and the government announced a smaller-than-feared rise in weekly stockpiles.
The market's focus on Iran nuclear talks, which had depressed prices since Friday, also shifted as the dollar eased. A weaker dollar makes commodities denominated in the greenback, such as oil, more attractive to holders of other currencies.
Crude production in the United States dropped 0.4 percent to 9.4 million barrels per day (bpd) in the week to March 27, the first weekly decline since the end of January, data from the Energy Information Administration showed.
Domestic inventories rose 4.8 million barrels last week to 471.4 million barrels, hitting record highs for a 12th straight week, the EIA said.
While a Reuters poll showed analysts had expected a 4.2-million-barrel build on average last week, some feared a bigger rise after industry group American Petroleum Institute suggested as much as 5.2 million barrels in a Tuesday report.
"Whatever the case, the production number is more important as its shows we could be at the cusp of a long-awaited trend in declining output from the drop in U.S. oil rig count," said Andrew Lipow, president at Houston-based Lipow Oil Associates.
The number of U.S. rigs drilling for oil have fallen to more than three-year lows since the selloff in crude began last June.
U.S. crude futures settled up $2.49, or 5.2 percent, at $50.09 a barrel.
Futures of North Sea Brent, the London-traded and more widely used benchmark for oil, settled up $1.99, or 3.6 percent, at $57.10.
In Switzerland, Iran and six world powers were closer to a preliminary accord on Tehran's nuclear program as marathon talks ran into Wednesday, but were stuck over key details such as lifting U.N. sanctions and Iran's future atomic research.
Iran produces about 2.8 million bpd, according to a Reuters survey, but is limited to exports of only 1 million bpd due to the sanctions. It is, however, keeping about 30 million barrels of crude on a fleet of tankers ready to be sold, if possible.
(By Barani Krishnan; Additional reporting by Himanshu Ojha in London and Jacob Gronholt-Pedersen in Singapore; editing by David Clarke and David Holmes, G Crosse and Marguerita Choy)