NEW YORK - The stock market was unstoppable in 2013.

A U.S. government shutdown, fear of a default, the threat of military action in Syria, big budget cuts, a European country looking for a bailout - any number of events might have derailed the stock market. But they didn't.

And if skittish investors had jumped out of stocks, they lost out.

The year "2013 would have been a good year to wear noise-canceling headphones," said Dean Junkans, chief investment officer for Wells Fargo Private Bank. "There were a lot of things that happened, and the market kept moving higher."

The Standard & Poor's 500 had its best year since 1997, gaining 29.6 percent. The Dow Jones industrial average gained 26.5 percent, its best annual gain since 1995.

Instead of worrying about the wider world, investors focused on the Federal Reserve and the outlook for its stimulus program.

The Fed bought $85 billion in government bonds each month in 2013. The purchases were designed to hold down long-term borrowing rates and encourage spending and investment. The stimulus also prodded investors to move from low-yielding bonds to stocks.

Investors reacted to every twist and turn of the program's fate. They sold stocks in the spring and summer over fear the central bank would slow its bond-buying prematurely. They worried that every bit of good economic news signaled the end of support.

But in December, as hiring grew consistently stronger, investors were confident enough in the economy that they reacted positively when Fed officials finally decided to dial back purchases. The Fed also reassured the market by signaling it would keep short-term rates near zero. The stock market, which hovered below all-time highs, returned to record territory.

Of course, it wasn't all about the Fed. Companies also played a part.

Despite a middling economy, U.S. corporate earnings rose for a fourth straight year. Total earnings for S&P 500 companies in 2013 are forecast to increase 5.37 percent, to a record $109.03 a share, according to data from S&P Capital IQ.

Investors, emboldened by the Fed's support and low inflation, were willing to pay more for those earnings. The price-earnings ratio for the S&P 500 index, a measure of earnings compared with stock prices, rose to 15.4 from 12.6 at the start of 2013, according to FactSet data. By that measure, stocks grew more expensive, but are not necessarily overvalued. The P/E ratio remained below its 20-year average of 16.5.

Here are some lessons from the year of the bull.

Small companies, big returns

Some of the best performers in 2013 were not the big blue-chip stocks, but smaller ones. The Russell 2000, an index that tracks small stocks, rose 37.1 percent, more than the Dow and the S&P 500. Smaller companies are more focused on the United States than multinational corporations. That means they benefit more when the United States grows faster than other parts of the world, such as Europe. That's exactly what happened in 2013.

Bond party is over

Yes, they were safe, but with 10-year Treasury notes paying interest below 3 percent for most of 2013, bonds were not sexy. From 1981 to 2012, the value of government and company bonds rose 35 percent, according to the Barclays Capital U.S. Aggregate Bond Index, a broad measure of the debt market. This year, bonds in the index handed investors a loss of 2 percent, the first loss since 1999.

Don't wait for dips

Even with all the unsettling headlines, 2013's stock surge was achieved without a significant wobble. The S&P 500 has gone 27 months without a correction, defined as a drop of 10 percent or more. That compares with an average streak of 18 months between such declines, according to S&P Capital IQ.

Hold the love

Signs of euphoria were largely absent from the stock market, despite the big gains. In fact, the market seemed out of step with a fragile economy.

The pace of mergers and acquisitions lagged as executives remained unwilling to strike large deals amid uncertainty about the economy. Corporate profits rose, but largely due to cost-cutting, not higher sales. Hiring picked up, but at a sluggish pace.

"I've never seen a near 30 percent year where investors are so unhappy," said Jonathan Golub, chief U.S. market strategist at RBC Capital Markets.

IPO market is back

The number of initial public offerings rose to its highest since before the recession in 2007, according to data from Dealogic as of Dec. 17. It's easier for companies to sell stocks in a climbing and steady market because investors are more confident they can make money.

The average IPO stock rose 35 percent in 2013, outperforming the S&P 500, according to Renaissance Capital data.

Hotel chain Hilton Worldwide and social media site Twitter went public. In total, companies sold $61 billion of stock in 2013, as of Dec. 17, an increase of 30 percent from 2012.

Change is constant

The 30-member Dow got a makeover in September, swapping out three old members for three new ones. It was the biggest shake-up for the blue-chip index in almost a decade. Out went aluminum producer Alcoa, Bank of America, and Hewlett-Packard. In came Nike, Goldman Sachs, and Visa. Despite its name, the Dow Jones industrial average is no longer dominated by industrial companies and now contains financial firms like JPMorgan and Travelers, as well as retailers like Home Depot and Wal-Mart, reflecting the changing nature of the U.S. economy.

Fed vs. Congress

While budget battles have rattled the markets before, investors started to get wise to Washington's habit of wrangling until the last minute before reaching agreements on the budget and other fiscal policy.

In 2011, lawmakers shook financial markets when they argued about raising the debt ceiling and pushed the U.S. toward default. The S&P 500 dropped 15 percent between July 20 and Aug. 10, 2011.

In 2013, investors stayed calm despite the first government shutdown in almost two decades and brinkmanship over the debt ceiling. After dipping briefly at the start of the shutdown, the S&P 500 rose 2.4 percent between Sept. 30 and Oct. 16, when a deal was reached.

"Not that Washington has yet become a positive, but I think that the bar got so low it was pretty much on the ground," said Liz Ann Sonders, chief investment strategist at Charles Schwab & Co.