Five years after Bernie Madoff admitted to masterminding the worst Ponzi scheme on record, JPMorgan Chase (JPM) agreed to pay more than $2 billion on Tuesday to settle criminal charges that the bank turned a blind eye to the massive fraud.

The deal with U.S. authorities includes a two-year deferred prosecution agreement and represents the largest-ever bank forfeiture in the U.S.

JPMorgan has additionally signed off on $543 million worth of settlements with investors hurt by the Madoff Ponzi scheme, including $325 million with Madoff Trustee Irving Picard. 

The Madoff settlements bring JPMorgan’s mounting legal tab up to about $20 billion over the last 12 months, a stunning figure that has eroded shareholder value and tarnished the bank’s reputation.

Click here to read about why investor advocates are blasting the Madoff settlement with JPMorgan

U.S. authorities announced criminal charges against JPMorgan for two felony violations of the Bank Secrecy Act tied to its relationship with Madoff, who is currently serving a 100-plus-year sentence in federal prison for masterminding an epic Ponzi scheme.

Under the terms of the deal, the criminal charges will be deferred for two years in exchange for JPMorgan admitting its conduct, paying $1.7 billion to victims of the Madoff fraud and agreeing to reform its anti-money laundering policies.

Preet Bharara, U.S. Attorney for the Southern District of New York, said JPMorgan as an institution “failed miserably” in the Madoff scandal.

JPMorgan also agreed to pay a $350 million penalty to the Office of the Comptroller of the Currency, which found "critical and widespread deficiencies" of the bank's anti-money laundering compliance programs. 

The OCC said the penalty is based on JPMorgan's failure to report suspicions about Madoff's investment firm to U.S. law enforcement and regulators despite alerting U.K. authorities. 

“J.P. Morgan failed to carry out its legal obligations while Bernard Madoff built his massive house of cards," FBI assistant director in charge George Venizelos said in a statement. "It took until after the arrest of Madoff, one of the worst crooks this office has ever seen, for J.P. Morgan to alert authorities to what the world already knew." 

In a statement, JPMorgan spokesman Joe Evangelisti said the bank recognizes "we could have done a better job" uncovering the Madoff fraud. JPMorgan said it does not believe any employee "knowingly assisted" Madoff's fraud. 

JPMorgan served as Madoff’s primary banker for over two decades and authorities believe the company ignored signs of the fraud.

In an email, a senior JPMorgan risk manager said another bank executive “just told me that there is a well-known cloud over the head of Madoff and that his returns are speculated to be part of  Ponzi scheme.”

"Madoff’s scheme was an unprecedented and widespread fraud that deceived thousands, including us, and caused many people to suffer substantial losses," Evangelisti said. "We believe the lessons we have learned will make us a stronger company."

Madoff pointed the finger at his former banker in the past. “There’s no question that JPMorgan is guilty; they would have to be idiots to not realize what was going on,” Madoff told FOX Business’s Adam Shapiro last May.

In Securities and Exchange Commission filing, JPMorgan said it expects the settlements announced on Tuesday to hurt fourth-quarter net income by about $850 million. The bank said it expects to add about $400 million to its litigation reserves for the fourth quarter. 

JPMorgan also said it has agreed to pay the Madoff trustee a total of $325 million in exchange for a release of all claims. The bank has additionally signed off on $218 million in payments to plaintiffs in a class action lawsuit tied to the Ponzi scheme. 

The funds will be used to compensate victims of the fraud. Both settlements are subject to court approval, JPMorgan said. 

The government said the $1.7 billion payment is the largest ever bank forfeiture and the biggest Department of Justice penalty for a Bank Secrecy Act violation.

Still, the punishment could have been even harsher. The government reportedly considered demanding a guilty plea from JPMorgan, although such a move could have jeopardized the company’s charter as a national bank.

The U.S. also decided not to pursue charges against individual JPMorgan execs, unlike in the London Whale trading scandal.

The JPMorgan settlement, coupled with a recent settlement by HSBC (HBC), demonstrates that the DOJ “does not intend to hold any bank officials accountable for facilitating money laundering through their financial institutions,” said Jimmy Gurule, who is a professor at the University of Notre Dame and previously worked as a former assistant U.S. Attorney General and Treasury Department undersecretary.

Shares of JPMorgan fell 1.27% to $58.25 on Tuesday, compared with a 0.64% gain for the S&P 500.

FOX Business reporter Peter Barnes contributed to this report.

Follow Matt Egan on Twitter @MattMEgan5