NEW YORK — Goldman Sachs said Thursday it had reached a roughly $5 billion settlement as part of a federal and state probe into its role in the sale of mortgages in the years leading up into the housing bubble and subsequent financial crisis.

It is by far the largest settlement the investment bank has reached related to its role in the crisis, but the payment dwarfs the payments 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 as part of the agreement. 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.

"We are pleased to have reached an agreement in principle to resolve these matters," Goldman 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. Goldman is scheduled to report its results on Jan. 20.

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.

Goldman shares fell 59 cents, or 0.4 percent, to $160.80 in aftermarket trading.