Updated

Bank of America has reached a settlement with Fannie Mae on residential mortgage loans sold by the bank and its Countrywide unit to the agency ahead of the nation's 2008 financial crisis.

The settlement includes a $3.6 billion payment to Fannie Mae. Bank of America will also buy back some of the loans sold to Fannie Mae for $6.75 billion.

Its stock gained more than 2 percent in premarket trading.

Bank of America bought Countrywide Financial Corp. in July 2008, just before the financial crisis. Countrywide was a giant in mortgage lending, but was also known for approving risky loans.

Bank of America Corp. also said Monday that it is also selling mortgage servicing rights on about 2 million loans.

The bank will take some charges, but expects "modestly positive" fourth-quarter earnings.