Bank of America agreed to pay bond insurer MBIA $1.7 billion to settle a dispute over faulty mortgage securities issued during the U.S. housing boom.

In exchange for the payment, the bond insurer will drop the litigation it brought against the mortgage lender Countrywide in 2008, according to a statement released by MBIA Monday. Countrywide was acquired by Bank of America in 2008. Also, MBIA will have no further payment obligations on any of its insurance policies held by Bank of America.

Bank of America has also agreed to lend MBIA as much as $500 million and has the option of buying a stake of up to 4.9 percent in the bond insurer.

“This comprehensive and important settlement is a very positive step forward for both Bank of America and MBIA,” Benjamin Lawsky, the New York Financial Services Superintendent, who helped broker the deal, said in a statement. “It resolves significant exposure and expensive litigation for Bank of America, while also giving MBIA a path forward.”

Bond insurers like MBIA and Ambac suffered big losses after the housing crisis. As defaults on mortgages rose, defaults on bonds backed by the troubled loans and insured by bond insurers also climbed. That led to a surge in payouts by the firms.

In a letter to shareholders March 19, MBIA CEO Jay Brown accused Bank of America of “dragging out” the litigation, putting at risk the insurers’ ability to pay its claims.

On Monday, Brown said in a statement he appreciated Bank of America’s efforts to arrive at a fair settlement and that the agreement was a significant milestone for his company.

For Bank of America, the agreement is another step forward in its attempt to clear up the legacy of its bad home loans.

In January, the lender reached an $11.6 billion settlement with government mortgage agency Fannie Mae to settle claims resulting from mortgage-backed investments that soured during the housing crash. In April, Bank of America agreed to settle a class-action lawsuit led by pension funds and other investors who say they were misled about $350 billion worth of mortgage-backed investments they bought from Countrywide.

MBIA surged $4.46, or 45 percent, to $14.29 on word of the deal. Bank of America also rose. The lender’s stock climbed 64 cents, or 5.2 percent, to $12.88.