Wall Street repeatedly bounced back from steep slumps, including the worst start to any year for stocks, the second correction for the market in five months and investor fears of a global slowdown. It also weathered plummeting oil prices and the surprising outcomes of Britain's vote to leave the European Union and Donald Trump's U.S. presidential election win.
A turnaround in company earnings growth, more stable oil prices, a steadily improving U.S. economy and job market all helped keep the market on an upward trajectory. More recently, investor optimism that the Republican election sweep will usher in a bevy of business-friendly policies spurred the market to new heights.
"It's been the year of the unlikely happening, but the crazy thing about the unlikely happening is you would expect that to lead to big sell-offs, and we experienced the exact opposite," said J.J. Kinahan, TD Ameritrade's chief strategist. "The more things happened that were unlikely, the more we seemed to rally."
The Standard & Poor's 500 index, the broadest measure of the stock market, closed out the year with a gain of 9.5 percent after an essentially flat finish in 2015.
Including dividends, the total return was 11.96 percent. That means if you invested $1,000 in an S&P 500 index fund at the beginning of the year you'd wind up with slightly less than $1,119.60 at the end of the year, after expenses.
Other major market indexes also delivered solid gains. The Dow Jones industrial average gained 13.4 percent, a surge that briefly had the 30-company average flirting with crossing the 20,000 mark. The Nasdaq composite notched a 7.5 percent gain.
Small-company stocks trounced the rest of the market, however, especially since the election. The Russell 2000 index soared 19.5 percent in 2016.
Investors anticipate that smaller companies will benefit more from an improving U.S. economy than their larger rivals because they tend to do far more of their business domestically. They also have fewer ways to dodge taxes through overseas subsidiaries, so they'll have more to gain if corporate taxes go down, and they'll also have less to lose if trade frictions flare up.
For the most part, markets overseas also fared better than in 2015.
In Europe, Britain's market closed the year at a record high that left the index with a 14.4 percent gain, despite jitters that rocked the market following the summer's "Brexit" vote to leave European Union. Indexes in Germany and France rose 6.9 percent and 4.9 percent, respectively. Japan's Nikkei and Hong Kong's benchmark index each eked out a gain of 0.4 percent.
Few anticipated the kinds of gains for U.S. stocks this year in January, when the market kicked of the year in a deep slump that knocked the Dow, Nasdaq and S&P 500 into a correction, or a drop of 10 percent or more from their recent peaks. For the S&P 500, it was the second correction in five months.
Fear that an economic slump in China could spark a global economic slowdown and alarm as the price of crude oil fell below $30 a barrel to its lowest level in 12 years triggered the market slide. Weak U.S. economic data didn't help.
The downturn was a surprise to many investors. Few expected another market correction so soon, and the Federal Reserve's move in December 2015 to raise interest rates for the first time in nearly 10 years signaled to many that the U.S. economy was healthy.
By the end of March, the market had started to regain its footing. By April, it recouped its losses and continued to mostly head higher. Then, toward the end of June, investors got blindsided by the Brexit vote. That dragged the market sharply lower and sent investors piling into U.S. bonds.
The slide lasted only a couple of days, and once again the market headed mostly higher.
Throughout the summer and into early fall, stocks rode an encouraging wave of developments: The U.S. job market continued to post strong monthly gains. Consumer confidence strengthened. More companies began to report better earnings and revenue for the third quarter, snapping a losing streak of five quarters for S&P 500 companies, according to S&P Global.
And crude oil prices stabilized, holding above $50. An agreement by OPEC and other major oil-producing nations to cut production next year in an effort to mitigate a glut in global supplies helped support energy prices. U.S. benchmark crude finished the year up 45 percent at $53.72 a barrel. That's far lower than it was in mid-2014, when it topped $100 a barrel.
The market jitters returned as the race between Trump and Hillary Clinton began to tighten, leading to a nine-day slump for stocks ahead of Election Day.
Wall Street had largely seen Clinton as more likely to maintain the status quo, while viewing Trump's polices as less clear. The billionaire's surprise win initially set off a sharp sell-off in Asian markets, signaling more pain for U.S. investors. But the opposite happened.
Global financial markets soon steadied and U.S. stocks kicked off a rally that extended well into December, driving the major U.S. stock indexes to record highs.
Investors are now betting that Trump and a Republican-controlled Congress will have a clear pathway to boost infrastructure spending, cut taxes and relax regulations that affect energy, finance and other businesses.
That agenda has flipped investors' priorities since the election away from defensive assets like bonds, utilities and phone companies, which traders had favored for much of this year, to financial, industrial and small-cap stocks.
It's also increased expectations of higher inflation and interest rates next year, which could make some fixed-income investments like bonds, less attractive.
The anticipation of higher interest rates led to a sell-off in bonds since the election that sent bond prices lower and drove up the yield on the 10-year Treasury note to the highest level in more than two years. The yield, which is used to set interest rates on many kinds of loans including mortgages, bottomed out at 1.36 percent in July and went as high as 2.60 percent in mid-December.
The move away from bonds, utilities and other safe-play assets is likely to continue as long as investors believe that Trump's economic policies will lead to economic growth and usher in higher interest rates.
"The investment landscape has changed due largely to the election," said Terry Sandven, chief equity strategist at U.S. Bank Wealth Management. "We're set up for equities."
December also saw the Federal Reserve boost its interest rate by a quarter-point. The central bank also signaled that it could begin to gradually raise interest rates as employment and inflation increase.
Even with the gains this year, market strategists say the current bull market, now in its seventh year, should continue, as long as company earnings continue to improve.
"As you look at 2017, the market is not cheap, so earnings have to grow, and they should grow," said David Chalupnik, head of equities for Nuveen Asset Management. "We have a year and a half to two years of the bull market left."