Goldman Sachs Group Inc has agreed to a settlement worth $1.2 billion to resolve a U.S.regulator’s claims the bank sold Fannie Mae and Freddie Mac faulty mortgage bonds, the regulator announced recently.

Under the settlement with the Federal Housing Finance Agency, the conservator for the two government-controlled mortgage finance companies, Goldman Sachs said it agreed to pay $3.15 billion to repurchase mortgage-backed securities from Fannie and Freddie.

The FHFA, which valued the settlement at $1.2 billion, said the accord “effectively makes Fannie Mae and Freddie Mac whole on their investments in the securities at issue.”

The $1.2 billion reflects the amount that Goldman will pay, minus the estimated current value of the securities being bought back from Fannie and Freddie.

The deal averts a Sept. 29 trial in a pair of lawsuits against Goldman that the FHFA filed in 2011 as it sought to recover damages from various financial institutions behind some $200 billion in mortgage bonds bought by Fannie and Freddie that later went sour.

To date, the FHFA has resolved all but three of the 18 lawsuits it filed, recovering $17.3 billion through cases against banks including Bank of America Corp, Deutsche Bank AG and Morgan Stanley.

The FHFA’s primary case against Goldman Sachs accused the bank of misleading the two mortgage finance giants in the sale of over $11.1 billion in mortgage-backed securities sold to Fannie and Freddie from 2005 to 2007.

Goldman Sachs denied the allegations, and in the settlement did not admit wrongdoing. Under the settlement, Goldman Sachs will pay about $1 billion to Fannie Mae and $2.15 billion to Freddie Mac, the FHFA said.

Goldman Sachs in a statement said the costs of the deal were substantially covered by its litigation reserves as of the second quarter of this year.

“We are pleased to have resolved these matters,” Gregory Palm, Goldman’s general counsel, said in a statement.

The deal tops a $550 million settlement that Goldman Sachs reached with the U.S. Securities and Exchange Commission to resolve charges over how it marketed a subprime mortgage product in 2010.

The U.S. Department of Justice continues to investigate Goldman Sachs over its marketing of mortgage-backed securities. The Justice Department on Thursday announced a $16.65 billion settlement with Bank of America over mortgage securities.

The FHFA continues to litigate against three other banks: HSBC Holdings Plc, Nomura Holdings Inc and Royal Bank of Scotland Group Plc.

HSBC continues to face its own trial Sept. 29, while Nomura’s case would go to a jury Jan. 26.

The case is Federal Housing Finance Agency v. Goldman, Sachs & Co. et al, U.S. District Court, Southern District of New York, No. 11-06198. (Editing by Leslie Adler)