Crude oil settled up 8 percent, or $3.71, at $48.24 on Friday, its best day since June 2012, after data showed U.S. drillers were slamming the brakes on the shale drilling boom.
The commodity still ended the month lower, for a seven-month decline.
Oil spiked $3 heading into the close on Friday as products were set to expire on the last day of the month and after oil companies made further cuts to capital expenditures and took more rigs offline.
Traders told CNBC they were acting on buy signals that technicals were showing heading into the weekend.
The number of U.S. rigs in operation fell by another 94 in the past week through Friday, while Canadian producers took 11 rigs offline, oilfield services firm Baker Hughes reported on Friday. Rig counts have been steadily falling as the price of crude collapses.
The rig count drop was the most since 1987. With drillers having idled about 24 percent of their oil drilling rigs since the summer, some traders may be betting that an anticipated slowdown in U.S. oil production is nearer than expected.
Two weeks of relatively stable oil prices have helped shift sentiment after months of decline, setting the stage for the violent rebound on Friday afternoon. Short traders raced to cover their positions on fears that the rout was nearing its end.
"The rig count number sparked the rally late,'' said Phil Flynn, analyst at Price Futures Group in Chicago.
Some traders were not convinced that the selloff in oil, which has taken Brent down from a June high above $115 a barrel, was over.
"There was a lot of short-covering before the month end from people wanting to take profit from the $40-odd lows, so it's not surprising that we rallied, said Tariq Zahir, managing member at Tyche Capital Advisors in Laurel Hollow in New York.
''But this doesn't change the fundamental outlook in oil. We are still about 2 million barrels oversupplied."
Benchmark crude contracts rose earlier in the day as concerns over fighting in Iraq extended short covering from the previous session, but crude prices were still poised for a seventh month of declines, the longest rout on record.
A supply glut and OPEC's refusal to cut output has driven benchmark Brent and U.S. crude futures down 60 percent since June. Chart watchers as well as analysts tracking market fundamentals believe the selloff will continue for a few more months at least.
A Reuters poll shows oil prices may post only a mild recovery in the second half of the year, with prices still averaging less in 2015 than during the global financial crisis.
Crude was up in early trading Friday in New York on renewed violence in oil producer Iraq, where Islamic State militants had struck at Kurdish forces southwest of the oil-rich city of Kirkuk.