Media playback is unsupported on your device Media caption The settlement is the biggest ever made by a US bank

JP Morgan has reached a $5.1bn (£3.2bn) settlement with the US Federal Housing Finance Agency (FHFA) over charges it misled mortgage giants Fannie Mae and Freddie Mac during the housing boom.

A separate settlement with the US Justice Department is expected to be announced soon.

"This is a significant step to address outstanding mortgage-related issues," the FHFA said in a statement.

It is the biggest settlement ever by a US bank.

In a statement JP Morgan said the settlement resolves the biggest case against the firm relating to mortgage-backed securities.

The bank added that the agreement relates to "approximately $33.8 billion of securities purchased by Fannie Mae and Freddie Mac from JP Morgan, Bear Stearns and Washington Mutual" from 2005 - 2007.

JP Morgan purchased Bear Stearns and Washington Mutual at the height of the financial crisis of 2008-2009, and has tried to argue that it should not be punished for mistakes made before those deals.

As part of the agreement with the FHFA, the bank will pay $4bn to Fannie Mae and Freddie Mac to settle claims that it violated US securities law.

It will pay the agencies an additional $1.1bn for misrepresenting the quality of single-family mortgages.

Fannie Mae and Freddie Mac are the biggest mortgage lenders in the US. They received $187bn in US taxpayer aid to help them stay afloat during the financial collapse.

They have since repaid $146bn of the loan.

'Broader resolution'

JP Morgan has been under investigation for several months by US regulators.

The bank said that it hoped the settlement would be part of a "broader resolution" of the firm's housing bubble woes - a nod to an expected settlement with the US Justice Department that is also likely to run to several billions of dollars.

The firm reported a rare loss last quarter, having set aside an additional $9bn to help it deal with its mounting legal troubles.

JP Morgan has set aside a total of $23bn to help the bank work through its many investigations by regulators in the US and abroad.

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.