By Ryan Dezember

Oil prices have shot up from the historic depths hit during the coronavirus lockdown, but analysts and traders worry the rebound has been too sharp and could prove short-lived.

Rather than surging on supply and demand fundamentals, oil prices have ridden along with other risky assets, such as stocks, that have been bid up by speculators looking to cash in on the U.S.'s emergence from the coronavirus shutdown.

"The short-term optimism on the oil market is exaggerated," said Commerzbank AG analyst Eugen Weinberg.

On Wednesday, West Texas Intermediate futures for July delivery gained 1.7% to close at $39.60 a barrel after the U.S. Energy Information Administration said the country's commercial crude stockpiles rose last week to their highest level ever. Brent crude, the global benchmark for oil, settled 1.3% higher at $41.73 a barrel.

They shouldn't be so high given swollen stockpiles and depressed fuel demand, Goldman Sachs Group analysts said. They have argued that oil prices have "mirrored the strength of the rally in financial markets, anticipatory assets entirely driven by expectations" rather than trading on supply and demand fundamentals, and are at risk of tumbling as much as 20%.

The U.S. benchmark dropped below $0 a barrel for the first time ever in April, when unburned fuel swamped the market. Prices have surged since. In both dollar terms and percentage gains, May was the best month on record for U.S. oil futures. They added another 11% during the first week of June as shelter-in-place orders relaxed, drivers hit the road and U.S. oil producers shut in wells and choked back output.

Prices also got a big lift after the Organization of the Petroleum Exporting Countries and its allies, such as Russia, agreed in April to reduce daily oil production by 9.7 million barrels to buoy prices and over the weekend extended the curtailment pact through July. Analysts also note a strategic buying binge by China, which stocked up on oil while prices were low.

Prices approaching $40 a barrel prompted U.S. producers to bring back curtailed production, which in turn has threatened the price recovery.

Analysts with Houston's Tudor, Pickering, Holt & Co. estimated that a million barrels a day of curtailed output will return to the market this month and that average daily production will rise by another 750,000 barrels in July.

"We sense investors may rather the industry wait a bit longer to allow fundamentals to firm further," the analysts wrote in a recent note to clients.

On Wednesday, the EIA said that gasoline consumption rose 4.6% last week, but that it remains off 20% from a year ago. Jet fuel consumption climbed 85% week over week but is still down 60% from last June.

Commercial stockpiles of crude oil, which excludes oil tucked away in the country's Strategic Petroleum Reserve, rose to 538.1 million barrels last week. That was up 11% from the same time last year and eclipsed the old high of 535.5 million barrels reached in March 2017.

Inventories swelled despite U.S. crude production declining for the 11th consecutive week. Daily output last week averaged 11.1 million barrels, down from a record 13.1 million in mid-March, according to the EIA.

Inventories had been expected to decline, not increase. Raymond James analysts said the weekly supply report was bearish for prices, but that it showed that the worst of the economic shutdown meant to slow the spread of the coronavirus was in the past.

"While it may not be realistic for demand to get back to pre-Covid levels until 2022, it is clear that the impact peaked in April," they wrote in a note.

Write to Ryan Dezember at ryan.dezember@wsj.com