US bank JP Morgan Chase has agreed to a record $13bn (£8bn) settlement with US authorities for misleading investors during the housing crisis.
It is the largest settlement ever between the US government and a corporation.
The bank acknowledged it made "serious misrepresentations to the public", but said it did not violate US laws.
"We are pleased to have concluded this extensive agreement," said JP Morgan boss Jamie Dimon in a statement.
About $4bn of the settlement is to go to homeowners hurt by JP Morgan's practices. This will be targeted at "keeping people in their homes", chief financial officer Marianne Lake said in a conference call.
Another $7bn will be paid to settle federal and state civil claims relating to misleading mortgage securities sold by the bank, Some of that will be given to investors who lost money.
The bank confirmed that this tranche of the settlement would be tax-deductible.
The remaining $2bn will be paid to the US government as a fine and will not be tax-deductible.
"The conduct uncovered in this investigation helped sow the seeds of the mortgage meltdown," said Attorney General Eric Holder in a statement.
Although the settlement effectively concludes the US government's civil investigation into the bank, a criminal investigation by the Department of Justice is continuing.
JP Morgan has worked hard to put the mortgage crisis of 2006-2007 behind it.
The bank has been under investigation for selling low-quality mortgage-backed securities to investors who were unaware that the securities often contained faulty mortgage products.
According to the statement from the Department of Justice: "JP Morgan employees knew that the loans in question did not comply with those guidelines and were not otherwise appropriate for securitization, but they allowed the loans to be securitized - and those securities to be sold - without disclosing this information to investors."
A large portion of the mortgages under investigation by authorities were bought by JP Morgan when it acquired banks Bear Stearns and Washington Mutual at the height of the financial crisis of 2008-2009.
"Today's settlement covers a very significant portion of legacy mortgage-backed securities-related issues for JP Morgan Chase, as well as Bear Stearns and Washington Mutual," said Mr Dimon.
Ms Lake said that 80% of the bad loans at the centre of the fine can be attributed to Bear Stearns and Washington Mutual.
The fine represents a sharp fall for JP Morgan, known for its so-called "fortress balance sheet" and traditionally strong reputation on Wall Street.
Mr Dimon was also a favourite with politicians in Washington, even being praised by US President Barack Obama.
Mr Obama told ABC News in 2009 at the height of the financial crisis: "There are a lot of banks that are actually pretty well managed — JP Morgan being a good example — I don't think Jamie should be punished for doing a pretty good job managing an enormous portfolio."
But that all seems to have changed in recent months.
Last month, the bank agreed to pay more than $1bn to help it end various investigations into its 2012 "London whale" trading debacle, which cost the bank more than $6bn and raised questions about its oversight procedures.
The firm also reported a rare loss last quarter, having set aside an additional $9bn to help it deal with its mounting legal troubles.
JP Morgan says it has set aside a total of $23bn to help it work through its many investigations by regulators in the US and abroad.
Worst behind them
Nonetheless, many investors seem to continue to think that the bank will emerge relatively unscathed from the fines.
"The share price is bumping up against a ten year high," Duff McDonald, author of a book on JP Morgan, told the BBC.
"While no one likes a fine especially of this magnitude, I think shareholders are responding positively to it because it's resolving some uncertainty around the company."
While the settlement with the US Justice Department does mean that the bank has put the worst of its expected fines behind it, there are still nine ongoing investigations by regulators into practices at the bank.
These investigations include that bank's hiring practices in China, as well as accusations that bankers at JP Morgan manipulated the Libor benchmark interest rate.