The regulator of Fannie Mae and Freddie Mac announced a $4 billion settlement with J.P. Morgan Chase (JPM) on Friday, closing a lawsuit related to mortgages sold during the housing boom.

The Federal Housing Finance Agency, which regulates the two mortgage-finance companies, initially sought $6 billion to settle the lawsuit alleging J.P. Morgan misled Fannie and Freddie about the quality of mortgages it sold them.

Under the deal, the nation’s largest bank will pay $2.74 billion to Freddie Mac and $1.26 billion to Fannie Mae to resolve claims related to securities sold between 2005 and 2007 by J.P. Morgan Chase and two firms it acquired amid the financial crisis: Bear Stearns Washington Mutual.

J.P. Morgan also came to separate agreements that resolve representation and warranty claims connected to single-family mortgage purchased by Fannie and Freddie. Combined, those deals total $1.1 billion.

J.P. Morgan intends to include the $4 billion FHFA settlement in a larger deal with the Department of Justice. The bank has been in talks over a $13 billion agreement to end several federal and state probes.

The Wall Street Journal reported earlier Friday that terms of the FHFA deal were struck during a phone conversation that included U.S. Attorney General Eric Holder and J.P. Morgan CEO Jamie Dimon.

A separate dispute between the bank and the FDIC had reportedly kept the deal from being completed. The two sides are at odds over how the costs of mortgage-backed securities issued by Washington Mutual will be handled.

JPMorgan acquired the banking operations of Washington Mutual in 2008 from an FDIC receiver and wants to maintain the ability to pursue the FDIC for WaMu-related liabilities.

The DOJ is said to be pushing for language in the larger deal to keep the FDIC from being responsible for any WaMu costs.

J.P. Morgan set aside another $9 billion in legal reserves in the most recent quarter, bringing the total to $23 billion. Last month, it agreed to pay more than $1 billion related to the “London Whale” trading fiasco, which cost JPMorgan $6 billion.

Follow Matthew Rocco on Twitter @MatthewRocco