Mortgage finance giants Fannie Mae and Freddie Mac are unlikely to need any more taxpayer money and will soon start paying back their loans, bringing the total cost of the government bailout of the firms to $124 billion by the end of 2014, according to federal officials.

To date, the companies, which play a central role in the Obama administration’s response to the housing crisis, have cost taxpayers $141 billion.

But soon, Fannie and Freddie will begin to generate enough profit to begin to pay back taxpayers. Nonetheless, officials say the companies are unlikely to ever repay all the money, cementing their status as the financial crisis’s most expensive legacy.

What’s more, if the economy worsens significantly, the companies might need $50 billion more in taxpayer aid, as profit would fall short of covering the losses associated with more homeowners falling into foreclosure.

The new projections from the Federal Housing Finance Agency come during a challenging time for the companies. The Obama administration and Republicans have said flatly that they want to get rid of the companies, which helped fuel the financial crisis.

But Fannie and Freddie are increasingly being called on to help carry out the government’s response to the housing crisis.

On Monday, for example, President Obama and regulators announced a plan to allow borrowers who owe more than their properties are worth to refinance at today’s ultra-low mortgage rates. Fannie and Freddie will carry out the program.

Still, the lack of a clear path for the companies’ future has demoralized employees. On Wednesday, Freddie Mac’s chief executive and three board members said they planned to step down in the coming year.

Fannie and Freddie were seized in fall 2008, as the financial crisis entered its most serious phase. No companies were more exposed than Fannie and Freddie, which own or guarantee trillions of dollars in mortgages.

Many of these mortgages were given to homeowners who could no longer afford to pay their loans. That created tens of billions of dollars in losses for Fannie and Freddie.

Federal officials seized the companies so they could continue their essential role in the operation of the mortgage markets, which provide money to banks so they can make home loans.

Fannie and Freddie have recently reached an inflection point. They have already suffered most of the losses associated with the financial crisis and are beginning to make a profit on the many new home loans they’ve bought or guaranteed since the crisis. These loans are much safer because Fannie and Freddie sharply narrowed eligibility criteria for mortgages.

Fannie and Freddie must pay a hefty 10 percent dividend on money they borrow from taxpayers. This has led to an unusual situation in which Fannie and Freddie must borrow money from taxpayers to pay taxpayers back.

In the end, though, these funds are a wash.