After all the turbulence of the past year, the solid rallies and breathtaking drops, the U.S. stock market, like any roller coaster, ended back almost precisely where it started.

At the end of a quiet trading day Friday, the Standard & Poor’s 500-stock index finished the year virtually unchanged (down 0.003 percent, to be exact). That was after rising on the year as much as 8 percent at one point (late April) and losing 13 percent at another (early October). Actual returns for stock investors were positive, however, once one accounts for dividend payments.

“The market gyrates and is very volatile, but here we are back to square one,” said Katherine Ellis Nixon, chief investment officer for personal financial services at Northern Trust.

The Dow Jones industrial average notched a stronger 5.5 percent return for the year, adding 640 points, while the Nasdaq composite index was down 1.8 percent. Treasury bonds had a very good year, with prices rising as yields fell. The 10-year bond yielded 1.88 percent Friday, down from 3.29 percent at the end of last year.

In effect, two forces were working at cross-purposes on financial markets in 2011. On one hand, the world seemed to become riskier as the year progressed. The European debt crisis escalated as leaders repeatedly failed to craft a solution, the U.S. government flirted with a national default and suffered an unprecedented downgrade in its credit rating, political upheaval roiled the Arab world, and economic growth showed signs of slowing in China and other emerging markets.

With the world a scarier place, investors demanded lower prices for stocks and other investments perceived as risky.

At the same time, though, the U.S. economy kept chugging along. Despite a soft patch in the summer, job creation and consumer spending showed resilience, continuing a gradual recovery.

That has been enough to drive corporate earnings up — and it is earnings that, over the long haul, determine the value of the stock market. Earnings per share of the S&P 500 are on track to rise 16 percent in 2011, with 328 of the 500 companies beating the earnings estimates of analysts.

“Those two forces have been offsetting each other, and for 2011 they have just about balanced each other out,” said Jerry Webman, chief economist of OppenheimerFunds, the giant mutual fund company.

Markets in the United States fared better than those in most of the world. The German stock market fell 14.7 percent for the year, and the Japanese market fell 17.3 percent. In that sense, the United States seems to have benefited from offering stability — even with its mediocre economic growth — in a tumultuous time.

That was even more vividly true in the market for government securities. Typically, the interest rate that the U.S. government must pay to borrow money declines when the stock market does. That’s because investors tend to put money into safe Treasury bonds, pushing down bond rates, at the same time they take it out of riskier stocks.

During the first half of the year, both stocks and bond yields rose. In July, they plummeted amid fears about Europe’s future and the U.S. standoff over whether to raise the federal debt ceiling. During the summer, depressed prices on stock and bond markets seemed to reflect a heightened expectation of a new recession.

But in the final months of the year, economic data suggested an improved outlook and the stock market revived, with a 14 percent rally since Oct. 3.

The bond market, however, has been little changed, with borrowing rates for the U.S. government remaining near all-time lows. With the European crisis unresolved, investors may see U.S. bonds as a safer bet than German or French bonds.

Fears over Europe’s outlook are also reflected in the declining value of the euro relative to the dollar. The currency for 17 European nations has fallen from $1.45 at the end of August to $1.29 on Friday.

Also, the Federal Reserve has been carrying out a program of buying longer-term bonds while selling shorter-term securities, known as “Operation Twist.” That, too, may be keeping bond yields from rising.

“If you look at the U.S. Treasury market and certain currencies, including the dollar, there is a remarkable flight to safety and to liquidity during times of uncertainty, and we’re clearly in a time of uncertainty right now,” Northern Trust’s Nixon said.