Much of the money from the mortgage giants, which is headed to Treasury, is from settlements and other onetime gains, the firms say. (Matthew Cavanaugh/EPA)

The mortgage giants Fannie Mae and Freddie Mac cranked out $10.2 billion in profits in the first quarter, money that will go to the U.S. Treasury in June under the terms of the government’s bailout of the firms at the height of the financial crisis.

Both companies said that a sizeable portion of their earnings were onetime gains derived mostly from settlements in lawsuits involving shoddy mortgages.

McLean-based Freddie Mac said the earnings are unlikely to be as strong in the future. Both companies cited the lawsuits and other onetime benefits as having boosted their profits, as well as gains in home prices, which are now starting to moderate.

“Our recent level of earnings is not sustainable,” Donald Layton, Freddie’s chief executive, said in a call with reporters Thursday morning.

Fannie Mae, which has been profitable for nine quarters in a row, reported income of $5.3 billion, with $4.1 billion of it from legal settlements in the quarter. Its smaller rival Freddie, which has been profitable for 10 consecutive quarters, announced of a profit of $4.5 billion and attributed $3.4 billion of that to legal settlements.

The government seized control of both companies in September 2008 to keep them solvent when the housing market unraveled. At the time, losses were piling up at Fannie and Freddie, and the government feared that those losses would cause the companies to collapse, sending global financial markets into a tail spin.

Fannie and Freddie have since received $188 billion from Treasury. By earlier this year, both had sent about $203 billion to the government in the form of dividends. With the profits announced Thursday, those totals climb to $213 billion.

However, because of the way the bailout is structured, the companies can never “repay” the taxpayers. In the early days of the bailout, Fannie and Freddie issued “senior preferred” shares of stock to the government that paid a 10 percent dividend in return for the cash infusion that the firms got from taxpayers.

But Fannie and Freddie were losing money at the time, and they were borrowing money from the Treasury to pay the 10 percent dividend. The government responded by scrapping that plan in August 2012 and demanded that Fannie and Freddie start sending all their profits to the government.

Investor groups are challenging that arrangement in court, and the government is facing more than a dozen lawsuits from such groups, including the mutual fund Fairholme Capital Management and the hedge fund Perry Capital Management.

To avoid a repeat of the bailout, the Obama administration is pushing to dismantle Fannie and Freddie and shift the risks of mortgage lending away from taxpayers to the private sector.

Sens. Tim Johnson (D-S.D.) and Mike Crapo (R-Idaho), the leaders of the Senate banking committee, have proposed legislation in line with the administration’s goals. The committee plans to vote on the bill soon. The bill’s advocates are working to win more support from panel members in advance of the final vote, hoping to improve the measure's chances of reaching the Senate floor.