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, and 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 jumped out of stocks, they lost out.

“2013 would have been good year to wear noise-cancelling headphones,” says 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 was up 30 percent, its best year since 1997. The Dow Jones industrial average also had a stellar performance with its best 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 fears 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.

“It’s tough to argue that companies are in anything other than good health,” says Paul Atkinson, head of North American equities at Aberdeen Asset Management, a global fund management company that oversees about $3 billion.

Here are some lessons from the year of the bull:

SMALL COMPANIES CAN GIVE BIG RETURNS

Some of the best performers in 2013 weren’t 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 larger multi-national corporations. That means they benefit more when the U.S. grows faster than other parts of the world, such as Europe. That’s exactly what happened in 2013.

THE BOND PARTY IS OVER

Yes, they were safe, but with 10-year Treasury notes paying interest below 3 percent for most of 2013, bonds weren’t sexy. From 1981 to 2012, 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.

As the economy improves, many investors believe that interest rates will continue to rise and bonds will only fall further.

DON’T WAIT FOR THE DIPS

Even with all the unsettling headlines, 2013’s stock surge was achieved without a significant wobble. The S&P 500 has gone more than 27 months, since Oct. 3, 2011, 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.

Investors who sat out the rally in stocks are left with a quandary: Do they buy now that stocks have become more expensive, or do they stay on the sidelines, waiting for a dip, and risk being left further behind?

A RALLY DOESN’T NEED TO BE LOVED

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,” says Jonathan Golub, chief U.S. market strategist at RBC Capital Markets.

Investors put $77.6 billion into U.S. stock funds in the first 11 months of the year, according to Lipper fund data. The last time investors put more money into stocks than they took out was 2005. But the inflows were only a trickle compared with the $451 billion withdrawn from stock funds between 2006 and 2012.

THE FED MATTERS MORE

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. Stock markets slumped before a deal was reached at the start of August and then plunged further as the Standard & Poor’s rating agency cut the nation’s debt rating days later.

In 2013, investors stayed calm despite the first government shutdown in almost two decades and brinksmanship over the debt ceiling.

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