Crude futures relinquished early gains ahead of the session's close on Monday as a global supply glut continued to cap gains while traders took profits after oil's earlier push higher.
U.S. crude closed up 27 cents, or 0.5 percent, at $51.91 a barrel. The contract rose to a session high of $53.10, which is just below its 100-day moving average at $53.18. It has not been above that key technical level since July 2014.
Front-month Brent crude was up 45 cents at $58.30 a barrel, having swung between $57.46 and $59.54.
Prices rose initially on concerns about turmoil in Yemen, the slowdown in U.S. drilling, and renewed expectations that it Iran would not be able to quickly add supply to the market if a deal is reached on Tehran's nuclear program.
The chief economist at the International Energy Agency, Fatih Birol, on Monday said it may take Iran three to five years to affect oil supplies. Oil growth may "surprise" this year, Birol said, noting that higher demand and lower supplies may put upward pressure on prices.
Weak export data from China raised concerns about the economy of the world's no. 2 oil consumer but also fueled hopes for economic stimulus along with data that showed China's crude oil imports were up 14 percent in March versus a year ago, though imports fell from February.
"Another case of bad news possibly being good news, since more stimulus for China would lead to more demand," said Phil Flynn, analyst at Price Futures Group in Chicago.
The market opened for Monday trading with momentum from Friday's strong finish on news that the number of U.S. rigs drilling for oil fell by 42 last week to 760, the largest decline in a month.
Adding support was news that speculators in Brent futures and options raised net long positions to the highest level since July 2014, in the week to April 7, data from InterContinental Exchange showed on Monday.
This followed Friday's news of a big jump in net long positions of U.S. crude futures and options in the same period.
But analysts at Germany's Commerzbank were unconvinced by the investors' bets.
"We believe the optimism among investors vis-à-vis oil is exaggerated," they said in a note on Monday.
"This has given rise to considerable correction potential which could lead at any time to a sharp fall in prices."
May futures for U.S. Ultra-low sulfur diesel, which received support last week from agricultural demand in planting season and export demand, got more lift on news that Colonial Pipeline shut down a pipeline running from Texas to North Carolina on Sunday .