Bank of America has agreed to the largest settlement in U.S. history, agreeing to pay $16.65 billion to end federal and state investigations into the sale of troubled mortgages.

The settlement, which was announced by the Department of Justice Thursday, was made after allegations that Bank of America, Merrill Lynch and Countrywide took part in schemes defrauding financial institutions and other investors in financial products (residential mortgage-backed securities), as U.S. Attorney Eric Holder explained to NPR.

Holder said the financial institutions knew the loans were fraudulent but marked them as reliable loans anyway.

Associate Attorney General Tony West told LA Times Bank of America was misleading investors about the securities and qualities of the mortgages.

"It's kind of like going to your neighborhood grocery store to buy milk advertised as fresh, only to discover that store employees knew the milk you were buying had been left out on the loading dock, unrefrigerated, the entire day before, yet they never told you," West said.

Bank of America CEO Brian T. Moynihan released a statement to the NY Times saying the bank believes this settlement is the option that is in the best interest of Bank of America shareholders. He added that by resolving the remaining mortgage-related exposures allows the bank to move on and focus on the future.