Goldman Sachs on Thursday said it reached an agreement in principal to resolve a long running government investigation into its sales of residential mortgage bonds in the run up to the financial crisis.

The total settlement is just over $5 billion, and will include $1.8 billion in consumer mortgage relief. Goldman gs said the consumer relief will include among other things principal writedowns for homeowners who are either behind or underwater on their mortgages, as well as financing for affordable housing.

Goldman said the settlement was not final. The Department of Justice, which reached the agreement with Goldman along with the New York and Illinois Attorney Generals and other regulators, could not be reached for comment. The settlement would resolve any civil claims the government has against Goldman for its role in packaging up home loans into mortgage backed securities and selling those bonds to investors. The settlement relates to MBS that Goldman sold from 2005 to 2007. Many investors who bought mortgage bonds during that time ended up with big losses.

Goldman said the settlement would lower its forth quarter earnings by $1.5 billion. Analysts had been expected the bank to make $1.65 billion in the quarter. The bank had previously set aside $1.4 billion for the settlement.

Goldman is one of the last banks to reach a settlement with the government over the financial crisis. Bank of America agreed to pay $16 billion in a settlement with the government in August 2014. J.P. Morgan Chase jpm reached a $13 billion settlement over mortgage bonds in late 2013. Goldman mortgage underwriting operation was smaller than those other banks. Back in 2010 it paid $550 million to settle charges brought by the Securities and Exchange Commission that it mislead investors into buying a so-called synthetic collateralized debt obligation named Abacus, which was made up of a bundle of financial instruments tied to subprime mortgage bonds, many of which plummeted in value shortly after the deal was sold.