Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

NEW YORK — Goldman Sachs said Thursday it will pay roughly $5 billion to settle federal and state probes of its role in the sale of shoddy mortgages in the years leading to the housing bubble and subsequent financial crisis.

Coming nearly eight years after the crisis, the settlement is by far the largest the investment bank has reached related to its role in the meltdown. But the payment is dwarfed by those made by some of its Wall Street counterparts.

Goldman will pay $2.39 billion in civil monetary penalties, $875 million in cash payments and provide $1.8 billion in consumer relief in the form of mortgage forgiveness and refinancing.

The U.S. Department of Justice, the attorneys general of Illinois and New York, and other regulators who are part of the settlement have not officially signed off on the deal, which could take some time.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

The government agencies are part of a joint state-federal task force created by President Barack Obama after the 2008 financial crisis that has extracted some of the largest settlements out of Wall Street.

Goldman, like other Wall Street banks, has been under investigation for allegedly misleading investors on the safety of the securities they created by bundling and selling mortgages.

Many of those poorly written mortgages went bad, triggering the financial crisis that spawned the Great Recession and the multi-billion government bailouts that have caused so much political anger in recent years.

"We are pleased to have reached an agreement in principle to resolve these matters," Goldman Sachs Group Inc. Chairman and CEO Lloyd Blankfein said in a prepared statement.

As a result of the settlement, Goldman said its fourth quarter earnings will be reduced by $1.5 billion. The firm earned $1.33 billion in its third quarter. Goldman is scheduled to report its results on Jan. 20.

A spokesman from the Department of Justice declined to comment on Goldman's announcement.

Goldman has been one of the last banks to settle with regulators for its role in the financial crisis. Bank of America, JPMorgan Chase and others all reached larger, more substantial settlements in 2014 and 2015.

Bank of America individually has paid out tens of billions of dollars in fines as a result of its role in the housing crisis. When JPMorgan reached a similar settlement with the same task force, it paid out $13 billion.

Goldman shares fell 9 cents to $161.30 in aftermarket trading.