By Christian Berthelsen 

U.S. oil prices surged more than 8% Friday as traders jettisoned bearish bets against the market after data showed a steep drop in the number of rigs drilling for oil in the country--a sign the wave of crude may be starting to ebb.

The news of falling domestic production facilities came against a backdrop of otherwise bearish supply-and-demand fundamentals and macroeconomic indicators on Friday, including a continued widening gap between production and consumption for oil from the Organization of the Petroleum Exporting Countries and a weaker-than-expected reading on fourth-quarter U.S. economic growth. Indeed, many analysts believe oil prices have further to fall as global production continues to outpace demand through the first half of this year.

Still, for one day the bullish production news drove traders to quickly unwind pre-existing bets that profit when the market falls. Such trades are closed out by buying futures to cover the position, which can feed into a price rally when it is done in large numbers at the same time.

The benchmark U.S. oil contract rose $3.71, or 8.3%, to settle at $48.24 a barrel on the New York Mercantile Exchange, the largest one-day percentage jump since June 2012. Most of the surge came in the last 45 minutes of trading as investors squared up their books with the end of the month.

The global Brent benchmark climbed $3.86, or 7.9%, to $52.99 a barrel on the ICE Futures Europe exchange, posting its largest percentage gain since April 2009.

Oil-field services company Baker Hughes reported domestic drilling rigs fell by 7% for the week, bringing the count to 1,223, the lowest level in three years.

"This is another sign that the drop in energy prices is going to impact future production of oil," said Phil Flynn, an account executive at Price Futures Group in Chicago. "People who have been short are starting to have second thoughts about staying short at this level."

The rally played into the positioning of traders who have been betting on a bounce in the market. Their numbers have been growing since late November as oil's price collapse has become more pronounced. As of Tuesday, bullish traders outnumbered bearish ones by more than 3-to-1, according to data from commodity regulators.

Before Friday's rally, U.S. and global oil benchmarks were down nearly 60% in the last seven months, as surging production from the U.S., Iraq and Libya overwhelmed tepid demand amid slowing global economic growth, and as OPEC kept output steady in a bid to defend its market share. Analysts believe the global oil surplus is rising by at least 1.5 million barrels a day. On Thursday, U.S. oil prices traded below $44 a barrel during the market session and settled at a nearly six-year low.

On Friday morning, the market received data pointing to a shaky global economic outlook, with fourth-quarter U.S. gross domestic product growing 2.6%, below the 3.2% average estimate of economists surveyed by The Wall Street Journal, and European price data signaling deflation.

While the global economy wobbles, OPEC says it produced 30.2 million barrels a day of crude oil in December, up 140,000 barrels from the previous month, despite declining demand for the cartel's output. Saudi Arabia made further reductions to selling prices for Europe and the U.S., and Iraq production is at or near four million barrels a day, according to London oil brokerage PVM Oil Associates Ltd. The market has seen back-to-back supply inventory surges in domestic oil stockpiles in the last two weeks, with production reaching a new 31-year high.

The global supply and demand imbalance is keeping the market in a funk. Both major contracts suffered declines for the seventh consecutive month, the longest losing streak since January 2009. Analysts said the selling could resume Monday with the start of the new month.

"We see ongoing headwinds for oil prices," Citigroup analyst Tim Evans said in a note. "Optimists may view the price performance in the face of bearish news as an encouraging sign, but we continue to see near-term downside risks."

In refined-product markets, gasoline futures gained 6.16 cents, or 4.6%, to settle at $1.4153 a gallon on the Nymex. Diesel futures snapped a 12-week losing streak, gaining 2.4% for the week and rising 6.79 cents, or 4.2%, for the day to end Friday at $1.6863 a gallon.

Write to Christian Berthelsen at christian.berthelsen@wsj.com