LONDON/NEW YORK (Reuters) - Royal Bank of Scotland RBS.L will pay $5.5 billion to settle one of the two major U.S. investigations into allegations it mis-sold mortgage-backed bonds that it needs to resolve before the British government can sell its shares.

The Edinburgh-based lender on Wednesday said it agreed to settle the lawsuit with the U.S. Federal Housing Finance Agency (FHFA) that accuses it of mis-selling $32 billion of mortgage-backed securities before the global financial crisis.

Analysts had previously estimated RBS would have to pay between $3.5 to $5 billion to settle the case with the FHFA.

“Today’s announcement is an important step forward in resolving one of the most significant legacy matters,” RBS Chief Executive Ross McEwan said in a statement.

McEwan has been trying to clean up RBS’s balance sheet and end an array of legal cases so the government can sell its more than 70 percent stake in the bank after a 46 billion pound ($59.6 billion) bailout during the financial crisis.

RBS said it will get a reimbursement of about $754 million from other parties and the fine is largely covered by existing provisions.

The bank said it will record a charge of 151 million pounds in next month’s result related to the fine.

Its shares traded almost 2 percent higher at 1255 GMT.

The case against RBS is the biggest and last of 18 lawsuits the FHFA filed in 2011 over about $200 billion in mortgage-backed securities that various banks sold to U.S. mortgage giants Fannie Mae FNMA.PK and Freddie Mac FMCC.PK.

The FHFA previously recovered $17.87 billion to resolve most of those lawsuits, including $5.83 billion from Bank of America Corp BAC.N and $4 billion from JPMorgan Chase & Co.

The FHFA contended that in buying the mortgage-backed securities from RBS, Fannie Mae and Freddie Mac relied on false and misleading statements contained in offering documents, leading them to suffer massive losses.

In September 2008, the U.S. government appointed the FHFA as conservator for Fannie Mae and Freddie Mac after seizing the mortgage financiers. Lehman Brothers Holdings Inc went bankrupt one week after that seizure.

The British government has said it will not resume selling its stake until the bank settles its U.S. fines and resolves its state aid requirements.

Taxpayers currently face a 29.2 billion pound loss on the value of the government’s shares in RBS, according to the Office for Budget Responsibility, Britain’s independent budget watchdog.