2017 has been an exceptional year for the stock market, and the Dow Jones Industrials (^DJI -0.98%) have already risen 5,000 points this year and look poised to keep climbing. Yet even though 20%-plus returns for stocks are impressive, what's arguably even more surprising is how an asset class that came into the year with far lower expectations managed to put together solid gains as well.

The bond market hasn't been a popular place to invest lately, with rock-bottom yields and high risks from a tightening Federal Reserve. But in 2017, long-term Treasury bonds -- the bonds that arguably have the highest potential exposure to rising rates -- managed not only to avoid losses but actually came close to reaching double-digit percentage returns after including interest.

TLT Chart

TLT data by YCharts.

How did bonds defy the Fed?

When 2017 started, most investors figured that bonds would have a terrible year. The Federal Reserve had already started raising interest rates, and most anticipated that the central bank would also start to reverse its quantitative easing moves by reducing the size of its balance sheet. Although the Fed's regular monetary policy targets short-term rates, an end to quantitative easing had ramifications for the long-term Treasury market. Many economists expected that Treasury yields would rise throughout the year, continuing their rise from late in 2016 and potentially bringing capital losses to bond investors that would wipe out meager returns from interest income.

Early in the year, the bond market behaved largely as investors had feared. By March, long-term rates had eclipsed where they had started the year, and as the Fed considered multiple interest rate hikes for 2017, bond investors started to think that the end was near. The long-Treasury focused iShares Barclays 20+ Year Treasury ETF (TLT -0.70%) dropped more than 3% between the beginning of the year and early March, spurring fears of much higher rates just in time for the spring home shopping season.

Old-style yellowed paper certificate with word Bond highlighted.

Image source: Getty Images.

Yet surprisingly, even though the Fed did continue to raise short-term rates, long-term Treasury yields reversed course and trended lower throughout much of the year. The steady, measured pace of monetary tightening encouraged bond market participants to anticipate a controlled rise that wouldn't shock the long end of the yield curve. By late summer, the 10-year Treasury had fallen from around 2.5% at the beginning of the year to near 2%, and 30-year yields that started 2017 well above 3% were below 2.75%. The iShares Treasury ETF not only recovered its early losses but climbed to gains of 8% at its best levels, even excluding interest payments. By late December, price gains had moderated somewhat, but the ETF still managed to post a total return including interest of nearly 10%.

^TYX Chart

^TYX data by YCharts

One support for Treasury prices came from international bond markets. Although rates were low by U.S. standards, bonds in Europe had even lower yields, with some countries still struggling with negative interest rates. That made bonds in the U.S. look attractive by comparison, and the resulting demand led to price increases even as the stock market soared.

Can 2018 be another strong year for bonds?

Investors still anticipate higher long-term interest rates, and so their views on where the Treasury bond market is likely to go remain bearish overall. It's hard to see how yields could fall from current levels, but it has been equally difficult to envision the rate declines that the booming U.S. economy has produced in recent years.

The same dangers that have been present for bonds for years are still present: If demand for bonds dries up, then soaring interest rates would produce substantial losses for bond investors. Yet coming into 2018, it appears that the Federal Reserve might well have found a way to return to a more normal monetary policy environment without spooking long-maturity bond investors. Don't expect bonds to match their 2017 performance in the coming year, but recognize that it's still a possibility despite the risks involved.