U.S. light, sweet crude futures rebounded from two days of sharp losses, ending more than 4 percent higher as the dollar weakened against the euro, prompting funds to switch assets to the oil markets.
The day's gain was the biggest percentage rise since March 26, and was partly fueled by a surge in technical buying after prices in late trading pierced the $125.10-high from the previous session, traders said.
Gasoline and heating oil futures also rebounded sharply, following heavy losses on Wednesday due to data showing larger-than-expected inventory increases last week.
On the New York Mercantile Exchange, July crude settled up $5.49, or 4.49 percent, at $127.79 a barrel, trading from from $121.61 to $128.26.
The gains wiped out the combined $5.46 loss in the two previous sessions.
The day's rally was due to "the dollar, bullish technicals and breaking out above $125.10," said Tom Bentz, analyst at BNP Paribas Commodity Futures in New York. Nymex crude futures hit a record $135.09 on May 22.
The dollar weakened against the euro, which rebounded from three-week lows set earlier in the session after European Central Bank President Jean-Claude Trichet signaled a rise in interest rates later this year. By midday, the euro hit fresh session peaks to extend gains against the greenback.
The dollar was on the rise before falling back on Thursday, helped this week by Federal Reserve Chairman Ben Bernanke saying the U.S. central bank was focused on the dollar's impact on inflation.
July London Brent also rose more than $5, climbing to more than $127 a barrel.
The Energy Information Administration said on Wednesday domestic crude stocks fell 4.8 million barrels last week, down for the third week in a row. But refinery utilization rose more than expected, by 1.8 percentage points to 89.7 percent of capacity, boosting gasoline and distillate stocks.
Gasoline demand fell 244,000 bpd, to 9.1 million bpd. In the comparable week a year ago, demand was at 9.5 million bpd.
In other news, BP was restarting an ultracracker at its 460,000-barrel-per-day Texas City, Texas, refinery, a source familiar with refinery operations said.