Bank of America (BAC) will pay $16.65 billion to settle a federal probe into its mortgage practices in the years leading up to the 2008 financial crisis.

The financial giant said Thursday that it has reached a deal with the U.S. Department of Justice and other federal agencies, along with six states, to resolve multiple investigations into how the company packaged and sold residential mortgage-backed securities. Such securities and related financial instruments were at the heart of the subprime lending bust.

Attorney General Eric Holder announced the settlement this morning.

Get Breaking News Delivered to Your Inbox

The deal is the largest financial settlement stemming from the housing crash, when the government was forced to bail out Bank of America and other large financial firms. In the last year, JPMorgan Chase (JPM) and Citigroup (C) have agreed to $13 billion and $7 billion settlements, respectively.

"This historic resolution -- the largest such settlement on record -- goes far beyond 'the cost of doing business,'" Holder said in a news conference. "Under the terms of this settlement, the bank has agreed to pay $7 billion in relief to struggling homeowners, borrowers and communities affected by the bank's conduct. This is appropriate given the size and scope of the wrongdoing at issue."

Bank of America will pay $9.65 billion in cash and provide borrowers with roughly $7 billion in mortgage relief. Just over $5 billion of the cash portion of the deal will consist of a civil monetary penalty, and $4.63 billion will be for compensatory remediation payments.

The $7 billion for borrowers will be used to lower homeowners' mortgage payments and for Bank of America to issue new loans. The company also will donate money to communities hit hard by the financial crisis and to provide financing for affordable rental housing. In addition, borrowers could be eligible for tax breaks if Congress fails to extend a 2007 law that offered mortgage relief to homeowners.

The Justice Department said an independent monitor will be appointed to ensure that Bank of America complies with the terms of the settlement.

"We believe this settlement, which resolves significant remaining mortgage-related exposures, is in the best interests of our shareholders, and allows us to continue to focus on the future," said Bank of America CEO Brian Moynihan in a statement.

Robert Hockett, a professor at Cornell Law School, said Bank of America was eager to resolve the government mortgage investigations. "BofA knows it is vulnerable and wishes to get this episode behind it as quickly as possible," he said by email.

Bank of America shares were up 29 cents, or 1.8 percent, to $15.81 in morning trade.

Most of the mortgage loans and securities that went bad at Bank of America came from its 2008 acquisitions of subrime lender Countrywide and brokerage firm Merrill Lynch, both of which had collapsed that fall following the shocking failure of Lehman Brothers.

Justice Department officials touted the size and scope of the latest settlement, saying it "achieves real accountability for the American people" and helps to reduce the harm caused by Bank of America's conduct during the housing bubble.

But Wall Street critics have decried the government's choice not to pursue criminal prosecutions of individual bankers for their role in the financial crisis, saying that even large monetary penalties are unlikely to deter future misconduct by big banks.

A recent survey by the Center for Responsible Lending, a non-profit that's often critical of banks, found that 78 percent of U.S. voters believe that Wall Street firms have yet to change their bad practices.

-- Jonathan Berr contributed to this report