Stocks overcame weeks of uncertainty, social unrest and a resurgence in coronavirus infections to finish one of Wall Street’s best quarters in history.

Two of the three major stock indexes are still down for the first six months of the year, and Federal Reserve chairman Jerome H. Powell on Tuesday cautioned that the economic recovery remains “extraordinarily uncertain” in the face of the stubborn coronavirus.

But indexes have rebounded from their March lows as investors placed their faith and money in the transformative power of remote technology and their belief that a slow but sure, broad recovery — backed by trillions in federal guarantees — is in the works.

The Dow Jones industrial average jumped 216 points, or about 0.9 percent, to close at 25,812.34. The Dow sealed a 16 percent comeback in the second quarter, leaving the blue chips 10 percent short of breaking even for the year. Apple, Home Depot, Dow and Microsoft muscled the index higher in the quarter.

The Standard & Poor’s 500 index jumped 1.5 percent during the session to cap its best quarter since the fourth quarter of 1998 — in the midst of the dot-com bubble — with a 19 percent gain. Energy, technology and discretionary spending — all industries tied to a broad economic recovery — led the S&P 500 for the quarter. The index closed Tuesday at 3,100.29 and is down 4 percent on the year.

“The second quarter revival was like Lazarus coming back from the dead,” said Howard Silverblatt of S&P Dow Jones Indices.

The Nasdaq — led by a handful of technology powerhouses — is up more than 11 percent on the year. Stay-at-home stocks such as Zoom, payments firm PayPal Holdings, online marketplace MercadoLibre and electric-car maker Tesla powered the index to a 30 percent surge for the quarter. The index ended the day at 10,058.76, ahead 1.9 percent.

The comeback follows a swift and frightening economic freeze caused by a virus that swept the globe, closing countries, demolishing economies and killing hundreds of thousands.

The broad S&P 500 index was down 31 percent for the year on March 23 after states shut down, telling people to stay home to contain the virus. The pandemic grounded airlines; closed schools, sporting events and businesses; and brought commerce to a standstill. More than 47.3 million Americans have filed jobless claims since March.

Much of Wall Street believes the economy bottomed out in April, followed by positive economic news that filtered up in May and June. Personal incomes rose 10.5 percent, thanks largely to federal stimulus checks, and unemployment filings leveled off. As more drivers took to the roads, the price of crude oil doubled in June, aiding a crucial industry that supports millions of jobs. The housing market is on the rise, thanks to record-low interest rates.

Early in June, a closely watched report on private payrolls showed 2.8 million jobs lost in May, far fewer than the nearly 9 million experts had predicted. The Bureau of Labor Statistics also issued surprisingly positive unemployment numbers, with the official rate dropping to 13.3 percent, an improvement from 14.7 percent in April. The agency releases June data on Thursday, just ahead of the holiday weekend.

“The Great Recession of 2020 may go down in history as the deepest but shortest recession,” said Kristina Hooper, chief global market strategist at Invesco.

Analysts said tens of millions of Americans participating in 401(k) retirement plans might feel more confident about spending when they see their quarterly statements.

“Many investors lived through 2008 and 2009, and learned from that experience the swiftness with which markets can rebound,” said Nicole Tanenbaum of Chequers Financial Management. “Those investors were rewarded for staying the course, and when they open their 401(k) statements later this month and see green numbers, they will again feel justified.”

Most investors have sat tight through the turmoil. From mid-February through the end of May, fewer than 1 percent of Vanguard’s household and retirement plan participants abandoned equities for safer harbors, according to Vanguard, which has $5.7 trillion under management.

“Very few people panicked,” said Vanguard senior investment strategist Jean Young. “And of those that traded, two-thirds bought equities instead of selling. Vanguard investors largely stayed the course.”

Fidelity Investments said its most recent data covering January through early May shows only a tiny number of individual investors in retirement plans sold out of stocks.

“Despite some significant market volatility earlier this year, most of our retirement savers stuck to their long-term savings plan,” said Fidelity spokesman Mike Shamrell.