The U.S. stock market ended 2020 at all-time highs, enriching the wealthy and capping off a soaring comeback despite a deadly pandemic that has killed more than 340,000 Americans and left millions jobless and hungry.

The S&P 500-stock index, the most widely watched gauge, is finishing the year up more than 16 percent. The Dow Jones industrial average and the tech-heavy Nasdaq gained 7.25 percent and 43.6 percent, respectively. The Dow and S&P 500 finished at record levels despite the public health and economic crises.

Wall Street’s resurgence has been fueled by the largest federal government stimulus ever, historic support from the Federal Reserve and optimism about how quickly the economy is likely to bounce back next year as coronavirus vaccines become widely distributed. Investors have largely ignored the pain on Main Street, including pronounced unemployment, overrun hospitals and battered small businesses. On the eve of the new year, nearly 20 million people remained on unemployment, a jobs crisis worse than during the Great Recession.

“That a pandemic-induced economic shutdown of epic proportion has been digested with stocks ending the year 15 percent higher is mind-blowing," said Michael Farr, president of Farr, Miller & Washington, a D.C.-based money management firm, adding: “2020 has been stunning."

Investors are focused on the future. Goldman Sachs predicts growth of 5.9 percent in 2021 — the best annual increase since 1984. And the unemployment rate is expected to fall to 5 percent, according to the Federal Reserve, meaning 2 million more people could return to work. Corporate earnings are forecast to balloon in the second half of the year, and crucially, analysts say, stocks remain appealing for many investors because interest rates are so low, making them more attractive than other assets such as bonds.

“Stocks are a forward-looking mechanism. They don’t care about what is happening right now or what happened in the past,” said Ryan Detrick, chief market strategist for LPL Financial. “So much of why stocks have done so well this year is looking ahead to a really significant economic bounce in 2021 as the economy opens up due to the vaccines.”

As the extent of the coronavirus became clear in March, investors sent stocks tumbling 34 percent, a bear market. But it turned out to be the shortest downturn in U.S. history. Since the U.S. stock market bottomed on March 23, the S&P 500 has risen 68 percent, shattering all-time records along the way. The rebound reflects Wall Street’s optimism about 2021, but it also underscores the disconnect between the stock market’s wild success and struggling American households.

“The markets are dominated by the folks who are in the upper echelons. They don’t feel any pain. They read about it, but they don’t experience it,” said David Kotok, founder of Cumberland Advisors. “What they do experience is the flip side: We have had very substantial productivity gains with Zoom and other daily life efficiencies."

President Trump has repeatedly heralded the gains, tweeting nearly 50 times about the stock market “up big” in 2020 and predicting a “big crash” if Joe Biden won the presidential election. In contrast, Biden and his team, including Janet L. Yellen, his nominee for treasury secretary, stressed that “the stock market isn’t the economy.

By the summer, the recession was largely over for the rich. The work-from-home crowd kept their jobs and experienced a major savings boost as they spent less on dining out, travel and entertainment. U.S. household savings increased by more than $1 trillion this year, driven by government stimulus checks and the wealthy not having much to spend money on. Economists predict that some of that savings will be spent in 2021, creating a major tail wind.

There’s “north of $1 trillion of accumulated saving,” Richard Clarida, vice chair of the Federal Reserve, said at a Brookings Institution event in November. “This is the only downturn in my professional career in which disposable income actually went up in a deep recession.”

In contrast, employment for low-wage workers remains about 20 percent below pre-pandemic levels, a staggering decline that has not improved in recent months, according to Opportunity Insights’ Economic Tracker. Economists began calling it a “K-shaped” recovery because of the diverging fortunes of the rich and poor.

“The recovery has been incredibly lopsided. High-income workers have been back to full employment for six months, but the recovery has stalled for low-income workers and we’re still missing millions of jobs," said John Friedman, a Brown University economist and co-director of Opportunity Insights. “If anything, things have gotten worse over the last few months for low-income workers.”

One in 8 Americans, more than 27 million adults, reported they sometimes or often didn’t have enough food to eat in the past week, according to Census Bureau survey data collected in late November and early December.

There are plenty of warning signs for the markets and the broader economy. Stocks are priced for perfection in 2021, analysts say, and any deviation from that rosy scenario could lead to a rapid correction or worse for investors. The biggest risks would be if the vaccine rollout stumbles or a new version of the virus emerges.

“We’re in one big experiment here. We don’t know when the virus end date will be,” said Diane Swonk, chief economist at Grant Thornton. “We need to get to herd immunity to fully heal the economy, but there are potholes in the road ahead."

The market’s gains have been driven largely by a handful of superstar stocks, a scenario eerily reminiscent of the dot-com era. Three of the biggest tech giants — Apple, Amazon and Microsoft — accounted for more than half of the S&P 500′s return this year, said Howard Silverblatt, senior index analyst at S&P Dow Jones Indices. (Amazon founder and chief executive Jeff Bezos owns The Washington Post.)

Absent the top 24 companies, dominated by tech and digital services, the S&P 500 return would be negative in 2020, Silverblatt added.

“The last time we saw such a skewing of tech dominance was toward the latter part of the tech bubble, which was unnerving,” said Sam Stovall, a U.S. equity strategist and market historian at CFRA Research. “The market is priced to perfection. I think it is vulnerable to some sort of trigger.”

Still, Stovall said the market historically has risen for at least three years after a bear market.

Investors are buoyed by Fed Chair Jerome H. Powell’s pledge to keep interest rates low for a long time, a scenario that favors stocks and corporate investment. Powell pledged in March to “do whatever it takes” to stabilize financial markets. He immediately cut interest rates to zero in mid-March and pumped more liquidity into markets than the Fed did in the wake of the 2007-08 financial crisis.

“Fed Chair Powell has been quite explicit that interest rates will stay close to zero for another three years," said Greg Valliere, chief U.S. policy strategist for AGF Investments. "That dwarfs everything else in importance.”

The Fed’s actions triggered a home-buying boom that sent prices to record highs.

Congress also has acted aggressively, approving $3.5 trillion in emergency relief and stimulus measures this year, the largest action in the face of a recession in U.S. history and one of the biggest aid packages in the world this year.

But much of the latest round of aid, especially for the unemployed and small businesses, is set to end in March and April, before vaccines are likely to be widespread enough for people to feel comfortable venturing out again.

“There will have to be another stimulus, because this pandemic is going to stretch into the spring,” Valliere said. “If Democrats take the two Senate seats in Georgia, there’s a much better chance of a significant stimulus bill.”

Some worry about the nation’s rising debt. Although it is incredibly cheap for the U.S. government to borrow money, the value of the U.S. dollar declined in 2020, sinking to its lowest point in more than two years. Analysts say it could be an early warning sign that global investors are concerned about the deficit and debt loads.

Another major concern is how many small businesses the United States has lost this year. About 4 million U.S. businesses closed in 2020, according to Oxxford Information Technology, driven mainly by restaurants, gyms and other small companies. It is exacerbating a trend that has been in progress for years: More Americans work for large companies than small ones. It’s a major change since the 1990s and early 2000s that is reshaping power in the business world.

“Just as there have been ‘haves’ and ‘have nots’ among households in America, there have been ‘haves’ and 'have nots’ among businesses in America," said Kristina Hooper, chief global market strategist at Invesco.

Gary Cohn, a former Goldman Sachs executive and top economic adviser to Trump, warned that part of the stock market’s gains were prompted by large corporations benefiting from the demise of small businesses.

“The stock market continues to reflect big businesses increasing their market share during #COVID19,” Cohn tweeted in August. “If a small business closes, a larger business fills the void. We need to contemplate what this means for Main Street USA going forward."

In addition to stock gains, the price of bitcoin, the cryptocurrency, nearly quadrupled in 2020, according to CoinMarketCap. Investors who dove in when the market sunk in March have seen the value of their digital tokens swell from about $4,000 to $28,000, a record. Many large-asset management companies began recommending the asset, pulling it further into the mainstream.

Optimism is growing about the prospects for the markets and economy in the second half of the year, driven by the hope of a return to life outside the home. But it remains highly uncertain how quickly jobs will return for the millions of low-wage workers in the restaurant, entertainment and travel industries that were hit so hard by the pandemic.

Some companies are watching sales climb without having to bring back staffing levels to pre-pandemic levels.

“If a few rich people are spending way more than before and many, many poor people are spending much less than before, the overall economy can look just fine. But a lot of people are still suffering,” said Friedman, the Brown University professor.

Kate Rabinowitz contributed to this report.