NEW YORK — The bull market in U.S. stocks just became the longest in history.

As of the market’s close Wednesday, the bull market that began in March 2009 has lasted nine years, five months and 13 days, a record that few would have predicted when the market struggled to find its footing after a 50 percent plunge during the financial crisis.

The long rally has added trillions of dollars to household wealth, helping the economy, and stands as a testament to the ability of large U.S. companies to squeeze out profits in tough times and confidence among investors as they shrugged off repeated crises and kept buying.

“There was no manic trading, there was no panic buying or selling,” said Jack Ablin, chief investment officer of Cresset Wealth Advisors. “It’s been pretty steady.”

The question now is when the rally will end. The Federal Reserve is undoing many of the stimulative measures that supported the market, including keeping interest rates near zero. There are also mounting threats to global trade that have unsettled investors.

For such an enduring bull market, it shares little of the hallmarks of prior rallies.

Unlike earlier rallies, individual investors have largely sat out after getting burned by two crashes in less than a decade. Trading has been lackluster, with few shares exchanging hands each day. Private companies have shown little enthusiasm, too, with fewer selling stock in initial public offerings than in previous bull runs.

Yet this bull market has been remarkably resilient. After several blows that might have killed off a less robust rally – fears of a eurozone collapse, plunging oil prices, a U.S. credit downgrade, President Trump’s trade fights – investors soon returned to buying, avoiding a 20 percent drop in stocks that by common definition marks the end of bull markets.

“I don’t think anyone could have predicted the length and strength of this bull market,” said David Lebovitz, a global market strategist at JPMorgan Asset Management.

One of the market’s biggest winners in recent years, Facebook, wasn’t even publicly traded when the bull market began. Facebook’s huge run-up of more than 350 percent since going public in 2012, Apple’s steady march to $1 trillion in value, and huge gains by other tech companies like Netflix have helped push the broader market higher.

Since the rally officially began on March 9, 2009, the Standard and Poor’s 500 has risen 321 percent. In the 1990s bull market, the current record holder for the longest, stocks rose 417 percent.

From the start, the Federal Reserve was a big force pushing markets higher. It slashed short-term borrowing rates to zero, then began buying trillions of dollars of bonds to push longer-term rates down, too. Investors frustrated with tiny interest payments on bonds felt they had no alternative but to pile into stocks.

Companies moved fast to adapt to the post-financial-crisis world of sluggish U.S. growth.

They slashed costs and kept wage growth low, squeezing profits out of barely growing sales. They bought back huge amounts of their own stock and expanded their sales overseas, particularly to China’s booming economy. Profit margins reached record levels, as wages sank to record lows as measured against the size of the economy.

“What people missed was how quickly U.S. corporations were restructuring and right-sizing themselves to regain profitability,” said money manager James Abate, who publicly urged investors to start buying stocks in early 2009 when most were dumping them. “It was really a catalyst for turning things around.”

China’s surging growth helped the market, too. Its boom drove up the price of oil and other commodities, helping to lift stocks of U.S. natural resource companies – for a while at least.

Then came a downgrade of the U.S. credit rating in August 2011, which caused stocks to swoon, and 2013 brought another fall as Fed Chairman Ben Bernanke talked of easing off stimulus policies. In the second half of 2014, oil plunged 50 percent, which rattled investors again.

Profits started falling the next year, but investors kept their nerve and didn’t sell and waited for profits to rise again. In 2016, stocks gained 10 percent, then jumped 19 percent the next year. Since the start of 2018, they have risen 6.6 percent, boosted by surging profits following the massive cut in corporate tax rates earlier this year.

Several dangers threaten the rally. The Fed has hiked its benchmark lending rate twice since January, and is expected raise it twice more by the end of the year.

Stocks could suffer as higher interest on bonds convinces investors to start shifting money into this safer alternative. Higher rates also increase costs for businesses and make expanding operations more difficult.

More worrisome, rising rates can trigger recessions, which often kill bull markets.