By Georgi Kantchev 

LONDON--Oil prices rose on Thursday after weekly U.S. crude oil supply data posted a surprise fall, offering a glimmer of hope that the oil glut might start to abate.

Prices have dropped sharply in July as persistently high U.S. production, coupled with record output from other major suppliers like Saudi Arabia, met worries about slowing demand exacerbated by this month's massive selloff in Chinese equities.

Brent crude, the global oil benchmark, rose 1.7% to $54.30 a barrel on London's ICE Futures exchange. On the New York Mercantile Exchange, West Texas Intermediate futures were trading up 0.9% at $49.22 a barrel. Both contracts are still off more than 20% since their peaks earlier in the spring.

On Wednesday, the U.S. Energy Information Administration reported that U.S. crude inventories fell by 4.2 million barrels last week defying analysts' expectations of no change.

U.S. oil production also fell, by 145,000 barrels a day to 9.4 million barrels a day, the largest one-week decline since October 2013.

"This was the most pronounced drop in production in recent years," said analysts at Commerzbank, apart from brief weather-related production outages. "Because the decline in production was not attributable to such special factors, it could prove sustainable."

According to consultancy Energy Aspects, early indications suggest U.S. output will be lower in the second half of the year based on earnings published so far, but the precise timing of the drop remains uncertain.

The number of oil drilling rigs in the U.S.--a rough proxy for activity in the industry--has dropped about 60% since October, but production has kept relatively stable so far.

"We still remain cautious about the weekly production figures as producers have been resilient in the face of lower prices and those with the poorest financials continue to raise output in order to ensure they meet lending requirements in October," Energy Aspects said.

Investor sentiment about crude oil remains bearish, however.

"Global oil production continues to surprise, with little sign of decline," said Robert Haworth, investment strategist at U.S. Bank Wealth Management which has $127 billion under management. According to Mr. Haworth, softer economic data out of Europe and China may indicate weak demand growth in the next couple of months.

"Prices are likely to remain weak until global production slows or demand accelerates," he said.

Nymex reformulated gasoline blendstock for August--the benchmark gasoline contract--rose 2.3% to $1.8639 a gallon. ICE gasoil for August changed hands at $497.50 a metric ton, up $1.75 from Wednesday's settlement.

Write to Georgi Kantchev at georgi.kantchev@wsj.com