The settlement requires JPMorgan to pay $9 billion and provide $4 billion in consumer relief, including principal reductions and other mortgage modifications for homeowners facing foreclosure.

New York Attorney General Eric Schneiderman, who sued JPMorgan in 2012, says the state will get $613 million in cash and about $400 million in relief for struggling homeowners.

For JPMorgan, the deal resolves some of the welter of investigations it is dealing with now. But even after the settlement, the bank faces at least nine other government probes, covering everything from its hiring practices in China to whether it manipulated the Libor benchmark interest rate.

JPMorgan said last month that it has set aside $23 billion to cover litigation expenses.

The deal resolves claims against JPMorgan, Bear Stearns and Washington Mutual before 2009.

For this settlement, JPMorgan took the unusual step of acknowledging that its employees knowingly sold loans to investors that were shakier than the bank claimed.

Due diligence firms that reviewed those loans for JPMorgan in 2006 and 2007 deemed that 27 percent of them were failing, but the bank still packaged at least half of those into mortgage securities, the government said.

“It had a direct impact on the mortgage industry, which led directly, I believe, to the collapse of our economy back in 2008 and 2009,” U.S. Attorney General Eric Holder said in an interview with NBC News’ Pete Williams.

A settlement had been expected for weeks but was held up repeatedly by disputes over the tax deductibility of the deal, who would pay for what elements and whether the bank would also be absolved of criminal liability.

The on-again, off-again talks were seen at risk of collapse late last month, but then got back on track a few weeks ago.

The deal is really several rolled into one. It includes a $4 billion relief package with U.S. Department of Housing and Urban Development, and a $4 billion settlement with the Federal Housing Finance Agency, which oversees government mortgage financing companies Fannie Mae and Freddie Mac.

Of the $4 billion settlement with HUD, at least $1.5 billion will go toward loans the bank is forgiving. As much as $500 million will go to change the terms of loans to lower monthly payments.

The remaining $2 billion will be for assorted purposes, including new loans for low- and moderate-income borrowers in areas that have been hard-hit by the housing crisis and for demolition of abandoned homes, a source told Reuters.

The country’s largest bank won’t likely face a criminal case, said former federal and state prosecutor Jacob Frenkel.

“I don’t think there’s really a real credible criminal probe [here], because the civil cases would not have been settled,” Frenkel said in a “Squawk Box” interview on CNBC, ahead of the formal announcement of the deal Tuesday.

Lawmakers and others have been critical of the administration’s failure to hold Wall Street banks, executives, and other parties accountable for the excesses that resulted in the housing crisis.

“You don’t get general deterrence until you hold individuals accountable, and in this settlement, there still is the missing culprit. No senior executive has been identified,” John Coffee, a professor at Columbia Law School, told NBC News.