JPMorgan Chase has reached a tentative agreement with the Justice Department to pay a record $13 billion to settle civil investigations into faulty mortgage securities the bank sold to investors in the lead up to the financial crisis, according to two people familiar with the negotiations.

The tentative deal was reached Friday night in a call involving Attorney General Eric Holder and JPMorgan Chase CEO Jamie Dimon, one of the sources said.

It would be the largest settlement ever between Justice and a single company.

The package is expected to include $9 billion in penalties paid to the government and $4 billion in relief for consumers.

The deal would mark a victory for the Obama administration, which has been criticized for not being more aggressive in pressing cases against Wall Street firms following the 2008 financial crisis.

For JPMorgan, the deal would be its latest, and most significant, attempt to settle a series of legal challenges from the government — investigations that are eating into the bank’s profits as well as its reputation as Wall Street’s best run bank.

The deal is not done and the final settlement is being negotiated through the mortgage securities task force President Barack Obama created in 2012, according to one source. This group is co-chaired by officials from Justice, the Securities and Exchange Commission and the office of New York Attorney General Eric Schneiderman.

In recent weeks, the bank has struck deals with various regulators intended to put an end to the firm’s legal woes.

Last month the bank agreed to a $920 million settlement with regulators over the London Whale trading debacle, along with separate deals over credit card and debt collection problems.

JPMorgan’s legal troubles caused it to this month report its first quarterly loss since Dimon became CEO in 2005. The bank reported that it lost $380 million in the third quarter after spending about $9.3 billion on legal expenses. It is now reserving roughly $23 billion for litigation costs.

Dimon has said that many of the issues with past mortgage bonds subject to the settlement with Justice and other agencies center around failing institutions — Bear Stearns and Washington Mutual — the bank took over in 2008 with encouragement from the government.

The government’s decision to press cases involving Bear and WaMu have clearly been a sore point for Dimon, but at this point JPMorgan appears to have decided its best to be done with the issue.

“It is very hard to fight with your regulators or the federal government, but we want them to be fair and reasonable,” Dimon told analysts on Oct. 11 when the company released its third quarter earnings.

As part of the tentative $13 billion deal, JPMorgan will pay $4 billion as part of an agreement with FHFA over mortgage-backed bonds the bank sold to taxpayer owned Fannie Mae and Freddie Mac in the lead up to the financial crisis, according to a source.

The FHFA sued JPMorgan and 17 other banks in 2011 alleging that the underlying loans in more than $200 billion worth of mortgage bonds sold to Fannie and Freddie were riskier than disclosed. The agency’s suit against JPMorgan covered roughly $33 billion in bonds sold between 2005 and 2007.

JPMorgan would become the fourth bank to settle the claims. UBS agreed in July to pay $885 million in its settlement. GE Capital and Citigroup reached settlements earlier in the year, but those amounts were not disclosed.

The deal with JPMorgan and the ongoing investigation into possible criminal charges would burnish the reputation of the president’s task force, which has been criticized for acting too slowly.

The SEC, under the umbrella of the working group, reached separate settlements with Credit Suisse and JPMorgan in November 2012.

There are still open cases against Credit Suisse and other firms, including a suit filed against Standard & Poor’s alleging the credit rating agency committed fraud when it stamped toxic mortgage bonds triple-A. A separate suit was filed against Bank of America and its affiliates, including Merrill Lynch, in August for allegedly defrauding investors in $850 million of mortgage-backed securities sold in 2008.