Royal Bank of Scotland has agreed to pay a smaller-than-expected $4.9 billion to resolve a U.S. investigation into its sale of mortgage-backed securities, paving the way for a long-awaited return of cash to UK taxpayers who bankrolled its post-crisis survival.

RBS said that $3.46 billion of the proposed civil settlement would be covered by existing provisions and that the bank would take a $1.44 billion charge in the second quarter to cover the rest.

Analysts had estimated the U.S. Department of Justice could impose a fine of up to $12 billion on RBS for mis-selling mortgage-backed securities in the run-up to the 2007-2008 financial crisis.

The agreement will draw a line under RBS’s last outstanding major litigation issue, which had weighed on its share price, blocked dividend distributions to shareholders and complicated the UK government’s plan to sell down its more than 70 percent stake.

Once the world’s largest bank by assets, RBS was one of the biggest casualties of the financial crisis which crippled credit, stock and housing markets and upended the global economy.

It narrowly avoided insolvency in 2008 after the UK government agreed a 45 billion pound bailout, just six months after the bank tapped 12 billion pounds of emergency cash from shareholders.

The government said in November it would begin the process of reprivatising the bailed-out lender by selling 3 billion pounds of shares before the end of the 2018-2019 fiscal year, in a much needed boost to finance minister Philip Hammond’s coffers.

Announcing the preliminary agreement on Wednesday, RBS Chief Executive Ross McEwan called the deal a “milestone.”

“Removing the uncertainty over the scale of this settlement means that the investment case for this bank is much clearer,” he said in a statement.

The U.S. Attorney’s Office in Massachusetts, which led the investigation, confirmed it had reached an agreement in principle with RBS that would resolve potential civil claims related to mortgage-backed securities issued between 2005 and 2008.

“Further details remain to be negotiated, however, before a formal agreement can be reached,” the office said.

The implosion of markets for residential mortgage-backed securities and related derivatives contributed to the global financial crisis and prompted a series of investigations by authorities including the U.S. Department of Justice.

The Department of Justice previously settled with banks including Citigroup, Deutsche Bank, JPMorgan Chase, Credit Suisse, Morgan Stanley, Goldman Sachs, Bank of America and Barclays .

The U.S. Attorney’s Office in Massachusetts had also been conducting a criminal investigation into RBS and former employees who were involved in structuring and selling the securities.

But the settlement that RBS and the office disclosed on Wednesday was only civil in nature, signaling no criminal charges were likely to result.

RBS in July 2017 agreed to pay $5.5 billion to resolve a lawsuit by the U.S. Federal Housing Finance Agency which claimed it misled the U.S. mortgage giants Fannie Mae and Freddie Mac into buying mortgage-backed securities.

It resolved similar claims by the U.S. National Credit Union Administration related to mortgage-backed securities RBS sold to credit unions that later failed for $1.1 billion in 2016.

Recently, RBS also resolved investigations by the state attorneys general of California and New York for $125 million and $500 million, respectively.

(Reporting by Nate Raymond and Eric Walsh, additional reporting by Sinead Cruise.)