After a three-year investigation, the Justice Department said Thursday that it had reached a $2 billion settlement with Barclays, a giant British bank that federal prosecutors say sold toxic mortgages that contributed to the global financial crisis.

Prosecutors say that between 2005 and 2007 Barclays sold investors packages of mortgages that were worth less than the bank claimed, costing the investors billions of dollars. More than half of the $31 billion in mortgage packages eventually defaulted, prosecutors said. The settlement “is an important step in recognizing the harm that was caused to the national economy,” Richard P. Donoghue, U.S. attorney for the Eastern District of New York, said in a statement.

But, for Barclays, the settlement may also be a triumph. The multibillion-dollar penalty could have been much bigger, industry analysts say. The bank also didn’t have to admit wrongdoing.

“The settlement came at the bottom end of expectations and much sooner than expected,” Ian Gordon, an analyst at Investec, said in a research note.

Barclays is paying much less than some other big banks who have faced similar allegations paid. In 2013, JPMorgan Chase paid $13 billion. In 2014, Bank of America agreed to a record-setting $16 billion settlement. Deutsche Bank paid $7 billion earlier this year.

The Barclays settlement was smaller, in part, because it did not include a requirement that Barclays provide relief to consumers, a common feature in the previous deals, industry analysts said. Keefe, Bruyette & Woods, an investment bank, said it had estimated Barclays would have to pay about $1 billion in consumer relief.

“This is marginally good news,” for Barclays, Keefe, Bruyette & Woods said in a research note about the deal.

Unlike many of those big banks, Barclays initially balked at paying a large fine. The Justice Department under the Obama administration was asking for as much as $8 billion from the British bank, according to industry analysts and media reports at the time. The Wall Street Journal reported then that the bank was being asked to pay about $5 billion. But Barclays wanted to pay much less, $1.5 billion to $2 billion, according to various media reports.

Photos from scenes of the 2008 global financial crisis

In remarkably grim language for a president known for his economic optimism, Bush defended the federal government’s “targeted measures” to shore up collapsing credit markets, but said there was an “urgent need” for even broader government intervention. “This is a pivotal time for America’s economy,” Bush said. (Melina Mara/TWP)

When they couldn’t reach an agreement, the Justice Department took the unusual step of suing Barclays in the waning days of the Obama administration. Then-Attorney General Loretta E. Lynch lashed out at the bank. “Barclays jeopardized billions of dollars of wealth through practices that were plainly irresponsible and dishonest,” she said.

But Barclays vowed to fight the lawsuit, saying it had an obligation to its shareholders to defend itself against “unreasonable allegations and demand.”

Fighting the case was potentially risky for Barclays, said Don Hawthorne, a financial industry litigator at Axinn, a New York law firm. The bank could have been found liable for up to the $15 billion in losses the Justice Department said its investors suffered from the faulty mortgages, he said.

But the Justice Department faced risks, too, he said. “They would have to make a case for fraud, which is never easy.”

Since Barclays is not a U.S. bank, and thus not a federally insured financial institution, the Justice Department faced potential challenges in applying the full force of an anti-racketeering statute, the Financial Institutions Reform, Recovery, and Enforcement Act, which it has used in similar cases, Hawthorne said.

It appears that President Trump’s Justice Department “lacked the enthusiasm of the previous administration to pursue this type of case and may have been reluctant to endorse an expansive interpretation of FIRREA,” Hawthorne said. “A reasonable reading of the circumstances would say that the attitude of the new administration likely played a role, and Barclays ultimately benefited from that.”

Barclays recently approached the Justice Department to restart negotiations, according to two people familiar with the matter, who were not authorized to speak publicly.

In a statement Thursday, Barclays chief executive Jes Staley said he was pleased to reach a “fair and proportionate settlement,” adding, “It has been a priority for this management team from the start to resolve these historic issues in a timely and appropriate manner wherever possible.”

The Justice Department also extracted $2 million from two former Barclays executives, Paul Menefee and John Carroll. But neither admitted wrongdoing, and both remained defiant despite the settlement. In a statement, Carroll’s attorney, Glen McGorty, called the allegations “meritless,” saying, “John Carroll is pleased that the Government has relented in its efforts to prove wrongdoing where none exists.”

Menefee agreed to settle the case so he could put the matter behind him, his attorneys said in a statement. “Paul Menefee has always maintained that the government’s lawsuit against him was baseless and should never have been brought,” attorneys Barry H. Berke and Dani R. James said. “As a Managing Director at Barclay’s Capital Inc., Mr. Menefee worked tirelessly, diligently and in good faith at all times on behalf of Barclays and its investors.”