Image caption The bank said the payments covered all outstanding and potential claims against it by Freddie Mac

Bank of America has agreed to pay US mortgage giants Fannie Mae and Freddie Mac about $2.6bn (£1.7bn) to settle claims it sold them bad home loans.

There had been fears the bank would be forced to buy back billions of dollars of mortgage loan investments.

"These actions resolve substantial legacy issues in the best interest of our shareholders," the bank's boss Brian Moynihan said.

Shares in the US's biggest bank closed up 6.5% following the announcement.

The bank said it had made a cash payment of $1.28bn to Freddie Mac and one of $1.34bn to Fannie Mae on 31 December.

It said these payments "extinguish all outstanding and potential mortgage" claims made against it by Freddie Mac, and "substantially resolves" those made by Fannie Mae.

"Bank of America believes that it has addressed its remaining exposure to repurchase obligations for residential mortgage loans sold directly to Fannie Mae and Freddie Mac," the bank said.

The claims relate to loans sold by Countrywide Financial Corporation, which Bank of America bought in 2008.

Fannie Mae and Freddie Mac said the loans were made without meeting investors' underwriting requirements, such as income levels and home values.

"This significant agreement with Bank of America is a fair and responsible resolution of these outstanding claims," said Fannie Mae boss Michael Williams.