The longest-dated municipal bonds are rallying the most in five years, attracting investors such as BlackRock Inc. and giving localities a chance to lock in lower borrowing costs for decades.

State and city debt due in 22 or more years has earned 6 percent in 2014 through April 1, the best annual start since 2009 and beating shorter maturities, Bank of America Merrill Lynch data show. The gains surpass the $3.7 trillion municipal market’s 3.8 percent advance. It’s a reversal from 2013, when the securities lost 6 percent and trailed other market segments.

Yields on benchmark 30-year munis fell this week to as little as 3.18 percentage points above two-year debt, the smallest gap since June, data compiled by Bloomberg show. As expectations persist for inflation to remain subdued, investors are more comfortable with longer-maturity tax-free bonds, which offer the most extra yield above Treasuries, said Sean Carney, a muni strategist at New York-based BlackRock.

“There isn’t likely going to be a tremendous amount of upside to growth or inflation from here, so it makes it easier to buy the long end of the curve,” said Michael Zezas, Morgan Stanley’s chief muni strategist in New York.

Fed Fuel

The demand for debt due in decades has helped issuers from California to New York reduce the expense of borrowing for capital projects and refinancing. California, with the second- lowest credit rating among U.S. states, sold $1.79 billion of general obligations last month, boosting the offer almost 6 percent and completing it a day early.

While longer-dated yields have fallen, interest rates on shorter-term debt jumped after a March 19 Federal Reserve forecast showed more officials predicting the benchmark rate, now close to zero, would rise at least to 1 percent at the end of 2015 and to 2.25 percent by the end of the following year, higher than previously forecast.

At the same time, the central bank’s preferred inflation gauge has been below its target for about two years. Restrained inflation preserves the value of longer-maturity bonds’ fixed payments.

“Investors seem less concerned about long-term inflation,” said Carney at BlackRock, which manages $108 billion of munis. “However, volatility has been created in the front end of the curve.”

Companies Too

Demand for longer-dated corporate bonds is also increasing. Company debt maturing in 15 or more years has earned 6.1 percent in 2014, beating shorter maturities and the 2.9 percent gain across the corporate market, according to Bank of America data.

In California’s sale, tax-exempt bonds maturing in December 2043 priced to yield 4.22 percent, or 0.33 percentage point more than benchmark munis. That spread was 0.46 percentage point in California’s October sale.

It was the first general-obligation borrowing after Governor Jerry Brown in January released a general-fund budget that projects the biggest surplus in more than a decade. Standard & Poor’s in January revised California’s outlook to positive from stable, citing Brown’s plan to pay down debt and build reserves.

The yield on the December 2043 debt in California’s latest sale was also almost 0.6 percentage point above the interest rate on benchmark Treasuries, showing how longer-dated munis give extra yield above federal bonds.

Treasuries Comparison

Interest rates on benchmark 30-year munis are about 3.7 percent, compared with 3.64 percent on similar-maturity federal debt. The ratio of the yields, at about 102 percent, compares with 81 percent on five-year securities. The higher the figure, the cheaper munis are on a relative basis.

“The excess premium as measured by the muni-Treasury ratio on the long end of the curve versus the short end of the curve is pretty substantial,” Zezas said.

Debt maturing in 20 to 30 years offers the best value because the yield difference between shorter maturities and longer-dated bonds will shrink more in 2014, Zezas said.

“It’s more Fed intervention on the short end and a lack of inflationary worries on the long end,” said Neil Klein, who helps manage $1.2 billion of fixed income at Carret Asset Management in New York.

The yield gap between the two- and 30-year maturities remains wide relative to historical trends. The difference has averaged about 2.6 percentage points for the past decade, about 0.6 percentage point below the current level.