WASHINGTON — Fannie Mae and Freddie Mac, the government-controlled mortgage finance giants rescued during the financial crisis, reached a deal with the Treasury Department on Thursday allowing them to keep some of their profits as they brace for losses that will be activated by the tax bill soon to be signed by President Trump.

Under the terms of the agreement, each company will be allowed to retain $3 billion from their earnings to serve as a capital cushion against future losses, including a decline in the value of their tax-deferred assets.

The arrangement is a change from the 2012 agreement that they reached with the Obama administration requiring that they send most of their profits to the Treasury as a condition for having been rescued by the Bush administration during the financial crisis. Fannie and Freddie required $187 billion of taxpayer aid in the 2008 financial crisis and were placed under government conservatorship as a result.

The firms, which buy or guarantee home loans, have been profitable for the last several years but are required to send almost all those profits to the Treasury, leaving the firms with little capital to protect against future losses. The $3 billion capital cushion is intended to help Fannie and Freddie deal with “ordinary income fluctuations” which could be exacerbated by the coming corporate tax cut. The drop in the corporate rate to 21 percent from 35 percent is expected to bring steep losses to Fannie and Freddie as they write down the value of their tax-deferred assets.