Wall Street rallied Thursday for its first gain in three days after a sudden surge in oil prices revived beaten-down energy stocks. But, as has so often been the case in this year's market sell-off, it took a few U-turns to get there.

The price of crude spurted as much as 30% higher after President Donald Trump said he expects Russia and Saudi Arabia to back away from their price war, which erupted last month and helped drag U.S. oil to its lowest price in 18 years. The surge lifted energy stocks enough to pull the S&P 500 higher and outshine another dismal report showing that millions of Americans are joining the unemployment queue by the week.

But stocks and oil quickly pared much of their initial gains and then see-sawed through the day as markets weighed how seriously to take Trump’s statement, particularly after the Kremlin reportedly disputed part of his tweet, before climbing again to the close.

By the end of trading, the S&P 500 rose 2.3%, while U.S. oil was up $5.01, or 24.7%, after settling at $25.32 per barrel.

The S&P 500 rose 56.40 to 2,526.90. The Dow Jones Industrial Average gained 469.93, or 2.2%, to 21,413.44, and the Nasdaq rose 126.73, or 1.7%, to 7,487.31.

“Investors are just grasping at a positive straw here on a particular day,” said Phil Orlando, chief equity market strategist at Federated Hermes. “The collapse in the energy market is creating a significant amount of additional pressure on the U.S. economy, not nearly as significant as the coronavirus, but significant nonetheless.”

The market’s focus has been on oil not just because its plunge to below $20 earlier this week from $60 at the start of the year has caused stocks in the industry to more than halve. Another worry is that heavily indebted oil companies will also be forced to default, which could cause more damage in the bond market where the total amount of debt has exploded.

Producers have been continuing to pull oil from the ground to maintain their market share, even as demand for energy cratered because of widespread stay-at-home orders and other economy-damaging restrictions caused by the coronavirus outbreak. Trump tweeted Thursday that he hopes and expects cuts in production are coming after talking with Saudi Crown Prince Mohammed bin Salman.

That helped energy stocks in the S&P 500 rally 9.1%, by far the biggest gain among the 11 sectors that make up the index. Schlumberger jumped 10.2%, EOG Resources rose 10.7% and Occidental Petroleum leaped 18.9%, though all three remain down between 50% and 70% for the year.

“This is a knee-jerk reaction more than anything else,” said Willie Delwiche, investment strategist at Baird. “I don’t think it changes much of the bigger picture for what we’re going through in terms of economic uncertainty and trying to wrap our minds around the extent of the weakness we’re going to see.”

Earlier in the day, the Dow Jones Industrial Average rose slightly after the opening bell Thursday, but then dropped nearly 200 points after newly released U.S. jobless numbers revealed the deeper impact of the coronavirus outbreak on the economy.

Investors initially appeared to react mildly to news of a record-shattering 6.6 million Americans filing for unemployment last week, according to the U.S. Department of Labor.

The new unemployment numbers shattered the previous record of claims set just the week before of 3.3 million, which was quintuple the prior record.

All three Wall Street indexes were modestly higher in early trading before tumbling.

The slow start to the day on Wall Street began after global stocks and U.S. futures were shown to be rising.

On Wall Street, futures for the benchmark S&P 500 Index and Dow Jones Industrial Average were both up 1.9%. The S&P 500 is coming off its worst quarter since 2008 with a 20% loss.

The hardest-hit stocks this week included banks, utilities and other dividend payers.

Department store icon Macy's has lost 74% in 2020. So much of its stock value has vanished that it was removed from S&P 500 index of big U.S. companies, effective Monday. It is being moved to the small-stock index.

U.S. investors were rattled by mounting evidence of the virus's impact on major companies and the economy as a whole.

The White House said 100,000 to 240,000 Americans might die of the virus even if the country avoids shopping and other public activities through April. That added to anxiety among investors who are trying to figure out how long and deep this history-making global economic downturn might be.

The number of infections is rising despite anti-disease controls that have shut down much of the global economy.

There are nearly 1 million confirmed cases worldwide, led by the United States with more than 206,000, according to a tally by Johns Hopkins University.

“Fear, fear and more fear descended upon the market,” said Jingyi Pan of IG in a report.

Traders say markets will be turbulent until numbers of new cases decline, but Pan said that “still looks to be a distance away.”