Goldman Sachs is still spending big money to clean up shady deals that fueled the financial crisis.

The elite Wall Street bank announced on Thursday it reached a $5.1 billion deal to put to rest claims made by the government over its toxic mortgage deals.

Goldman Sachs (GS) has been accused of cobbling together home mortgage securities it knew would implode and then selling them to unsuspecting investors. Goldman's handling of these deals prompted Rolling Stone magazine to infamously call the bank the "great vampire squid" of Wall Street.

Goldman said it has agreed to pay a $2.4 billion civil penalty, pay $875 million in cash and provide $1.8 billion in consumer relief.

The bank said the consumer relief will include loan forgiveness for underwater homeowners and distressed borrowers as well as support for affordable housing.

"This cleans up a piece of the company that took eight years to clean up. It's finally gone," said Dick Bove, a veteran banking analyst at Rafferty Capital.

Goldman expects the deal to dent its fourth-quarter profits by about $1.5 billion after taxes.

Related: What crisis? JPMorgan Chase reports $5.4 billion profit

The settlement was reached in principle between Goldman and a task force that includes 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 securities were cobbled together and sold between 2005 and 2007.

Other Wall Street firms have reached similar deals in recent years, including JPMorgan Chase (JPM) and Morgan Stanley (MS).