In the largest deal ever between a single company and the U.S. government, banking giant JPMorgan Chase tentatively agreed to a $13 billion deal to settle federal investigations into bad mortgage loans. (Reuters)

JPMorgan Chase, the nation’s largest bank, has reached a tentative agreement with the Justice Department to pay a record $13 billion to resolve allegations that it knowingly sold faulty mortgage securities that contributed to the financial crisis, a person familiar with the talks said Saturday.

If finalized, the deal would be the largest penalty ever paid by a single company, representing a tremendous win for the government after years of public criticism over its struggle to hold Wall Street accountable for its crisis-era misdeeds.

It would also leave JPMorgan and its executives still at risk of criminal prosecution, a humbling concession. The bank emerged from the financial crisis relatively unscathed but has struggled to shake off the vestiges of that era. Like many banks, it has been accused of selling bad residential mortgages to investors, including Fannie Mae and Freddie Mac, which lost billions when the housing market crashed.

JPMorgan and the Justice Department have been negotiating a potential deal for months, but talks heated up a few weeks ago and eventually included direct discussions between the bank’s chief executive, Jamie Dimon, and Attorney General Eric H. Holder Jr.

The stakes are high for both sides. Pulling off a record settlement would be a significant accomplishment for Holder. The Justice Department has levied multimillion-dollar fines against big banks, including HSBC and Barclays, but to lawmakers and consumer advocates, those penalties are tantamount to a slap on the wrist.

“Resolving the mortgage cases for $13 billion is a major win for the DOJ, particularly since the deal only applies to the civil case,” said Thomas Gorman, a securities lawyer at Dorsey & Whitney. “It also brings to account a major Wall Street player for the market crisis, something enforcement officials and the public have been looking for.”

JPMorgan is urgently attempting to wrap up a barrage of investigations into its conduct in recent years, leading the bank to agree to pay billions to settle various cases in recent months. Dimon, once considered the sage of Wall Street, has taken a conciliatory tone with regulators and has called the legal fallout “painful” for him and the company.

The deal could be finalized soon, according to a person familiar with the negotiations who was not authorized to speak publicly. The Justice Department and JPMorgan are hammering out the final details, including a statement listing what the company did wrong. Such an admission of wrongdoing could be used in other legal actions against the bank, making it a significant sticking point during the talks.

Officials at JPMorgan and the Justice Department declined to comment.

Selling mortgage securities was a brisk business for Wall Street for many years. Banks, after issuing loans to home buyers, would pool hundreds of mortgages and market the bundles as investments that could be traded like stocks. When the housing market crashed, the securities were worthless and left investors saddled with massive losses.

A key issue during the discussions has been whether JPMorgan and its executives would face criminal prosecution for allegedly knowing that the bank was selling bad mortgages, the person said.

“JPMorgan had been trying to get amnesty for criminal prosecution,” the person familiar with the negotiations said. But Holder, in a phone call this month with Dimon, said “that was a non-starter,” the person said.

On Monday, Associate Attorney General Tony West reiterated the Justice Department’s position to the bank’s general counsel, Stephen Cutler. The next day, JPMorgan officials told the bank’s board of directors that the department was not willing to give the company a criminal release, the person said.

Dimon called Holder on Thursday with a new offer. The bank had previously offered $11 billion, which the Justice Department rebuffed. On Friday, Dimon, Cutler, West and Holder agreed to a civil settlement during a conference call.

The criminal investigations into the bank and individuals involved with the sale of the mortgage securities will go forward, said the person familiar with the negotiations.

The full scope of the deal is unclear, but it would include $4 billion in relief to homeowners, including lowering how much they owe on their mortgages.

Another $4 billion would go to the Federal Housing Finance Agency, which regulates Fannie Mae and Freddie Mac, to resolve allegations that JPMorgan made false statements and omitted facts about the quality of home loans it sold the mortgage finance twins. Fannie Mae and Freddie Mac, which purchase and insure mortgage securities, received $188 billion in taxpayer bailout money during the crisis.

JPMorgan is among the 18 financial firms sued by the FHFA in 2011 to recoup losses sustained by Fannie and Freddie from securities bundled with poorly underwritten home loans. The agency has settled three of those cases, including a $885 million deal with UBS in July.

The tentative JPMorgan deal would also end a California civil probe, as well as a separate lawsuit filed by New York Attorney General Eric Schneiderman in October over shoddy mortgage securities.

JPMorgan disclosed in August that it was responding to “a number of subpoenas and informal requests” from federal and state authorities concerning the packaging and sale of mortgage securities.

At the time, the company said government attorneys had concluded that JPMorgan broke federal laws in its handling of subprime and other risky residential mortgages.

Many of the probes stem from JPMorgan’s Bear Stearns unit. Dimon has decried the government’s probes of Bear Stearns in the past, insisting that his bank was being punished even though its acquisition of the firm helped government efforts to save the economy. Dimon has said that JPMorgan has already paid nearly $10 billion to unwind Bear Stearns’s troubled businesses and settle litigation related to the firm.

For the venerable JPMorgan, arguably the big bank that emerged strongest from the crisis, to even consider paying $13 billion to the government shows that the bank is beleaguered, analysts say.

A resolution with the Justice Department would reduce but not end the legal headaches at JPMorgan. The financial goliath is also embroiled in federal probes into tactics used to collect credit card debts and its role in the ma­nipu­la­tion of a key interest-rate benchmark that affects trillions of dollars of bonds, among other matters.

The barrage of federal investigations and multibillion-dollar settlements led JPMorgan on Oct. 11 to report its first loss in nearly 10 years. The bank suffered a net loss of $380 million after setting aside an additional $9.2 billion for future litigation expenses. All told, the bank has a $23 billion chest to cover its mounting legal costs.