Bank of America's purchase of mortgage lender Countrywide Financial at the height of the financial crisis in 2008 may go down as one of the most short-sighted acquisitions ever made. According to The New York Times, BofA has suffered "more than $40 billion in losses on real estate, legal costs, and settlements" related to Countrywide, which made a tidy profit off subprime mortgages and other toxic assets during the halcyon days of the housing bubble. And now comes a $10 billion settlement that BofA reached on Monday to settle claims that Countrywide had sold bad mortgages to Fannie Mae, the government-controlled mortgage financing company.

Under the deal, BofA will pay Fannie Mae a $3.6 billion fine. And another $6.8 billion will be used to repurchase mortgages from Fannie Mae that Countrywide had allegedly offloaded by falsely claiming they were high-quality mortgages.

In addition, BofA was among a group of 10 lenders who reached a separate, $8.5 billion settlement with federal regulators on Monday to resolve allegations that they had pushed through foreclosures without the proper paperwork.

All in all, it was a rather costly day for BofA. But executives at the mega-bank are breathing a sigh of relief, because the Fannie Mae case was the biggest legal liability that BofA had left from the housing crisis. CEO Brian Moynihan said the settlement with Fannie Mae was "a significant step" in the bank's campaign to resolve its legal problems and further scale back its presence in the housing market. 

BofA still faces a suit from the Justice Department that could result in another billion-dollar settlement. However, it appears that BofA is finally emerging from a long period of litigation that had shrouded the company's future in uncertainty. "While cleaning up the bank will require more than just throwing money to make lawsuits go away, Moynihan knows removing uncertainty is a big part of the game," says Halah Touryalai at Forbes. "And that's what exactly what today's $10 billion suit does."