Bank of America Corp. has agreed to an $11.7 billion package designed to resolve most disputes with U.S.-owned Fannie Mae over bad mortgages after a deal announced two years ago proved inadequate.

Bank of America will make a $3.6 billion cash payment, spend $6.75 billion to buy back residential loans sold to Fannie Mae, and pay $1.3 billion in fees for taking too long to foreclose on overdue borrowers, according to separate statements Monday. Even after these costs and an additional $2.5 billion for expenses that include litigation and a separate regulatory settlement, the Charlotte, North Carolina-based lender said the fourth quarter was “modestly” profitable.