Bank of America Corp agreed to settle outstanding claims on poorly underwritten mortgages it sold to government sponsored entities Fannie Mae and Freddie Mac, and said it will put aside $3 billion in the fourth quarter related to the claims.

Shares in Bank of America climbed 3.5 percent in premarket trading. Investors were worried that the bank, like other large mortgage sellers, may have to buy back billions in mortgages it sold with faulty paperwork and other problems.

The bank made a $1.28 billion cash payment to Freddie Mac, as part of the agreement to end all claims related to mortgages sold by Countrywide, a mortgage company bought by Bank of America, through 2008.

The bank paid Fannie Mae $1.34 billion in a similar agreement that settles claims on 12,045 Countrywide loans.

Bank of America also expects to record a fourth-quarter $2 billion goodwill impairment charge in its home loans and insurance business unit.

Fannie Mae said in a statement that the agreement with Bank of America addresses about 44 percent of its $7.7 billion in outstanding repurchase requests at the end of September.

The agreement is similar, though much larger in scale, to a recent $462 million settlement Ally Financial Inc made with Fannie last month.

Charlotte, North Carolina-based Bank of America is still working through claims related to mortgages sold to private investors.

(Reporting by Elinor Comlay; Editing by Derek Caney)