Goldman Sachs Group Inc said on Thursday it would pay over $5 billion to settle claims it misled mortgage bond investors during the financial crisis, a move that will cut the firm's fourth quarter earnings by about $1.5 billion.

Goldman Sachs said the settlement comprises a $2.385 billion civil penalty, a $875 million cash payment and $1.8 billion in relief for homeowners whose mortgages exceed the value of their property as well as distressed borrowers.

The agreement resolves actual and potential claims from the U.S. Department of Justice, the New York and Illinois Attorneys General, the National Credit Union Administration and the Federal Home Loan Banks of Chicago and Seattle.

The hit to earnings comes after Goldman Sachs took a $1.45 billion provision in the second quarter in anticipation of a deal.

The settlement underscores how Wall Street has yet to shake off the legacy of the U.S. subprime crisis, when mortgages were sold to people who could not afford them and then repackaged for investors without an adequate explanation of how risky they were.

The agreement has been made in principle and has to be finalised with the regulators and other bodies involved. It was not clear how the civil penalty and cash payment would be divided among the different parties to the deal.

The agreement relates to mortgage bonds sold between 2005 and 2007.

The U.S. Department of Justice and state officials have already extracted multi-billion dollar settlements from a number of large U.S. banks including JP Morgan, Bank of America and Citigroup over the sale of mortgage-backed securities.

The Goldman settlement is at the lower end of previous penalties. Bank of America reached a $16.65 billion settlement in 2014 while JP Morgan settled for $13 billion in 2013.

Goldman Sachs will report fourth-quarter earnings on Wednesday. Its shares were marginally down in extended trading on Thursday.

(Reporting by Sudarshan Varadhan in Bengaluru and Suzanne Barlyn in New York.; Editing by Don Sebastian, Carmel Crimmins and Andrew Hay)