Government-backed mortgage giants Fannie Mae and Freddie Mac have spent nearly $100 million since 2004 to defend three former executives from lawsuits and other investigations, part of a mounting set of legal bills for the troubled companies, according to a newly released report from the inspector general of the Federal Housing Finance Agency.

The payments, which were included as part of compensation and benefits packages provided to officers and directors at Fannie and Freddie, underscore the uncomfortable and conflicting role the government faces as conservator for the firms, whose bad bets on risky home loans before the financial crisis have cost taxpayers more than $130 billion. Under those compensation agreements, Fannie and Freddie are obligated to pay all legal expenses for the executives involved, including advance payments for expenses incurred during the course of legal proceedings.

That means the independent FHFA, which oversees Fannie and Freddie, has the unenviable role of trying to help the mortgage companies avoid losses by defending ongoing lawsuits, while simultaneously trying to keep down the hefty costs of attorneys fees for former employees. It is a bind that appears to have no easy solution. In fact, the FHFA’s inspector general offered two recommendations in Wednesday’s report that will prove easier in theory than in reality — work to limit legal expenses to the extent “possible and reasonable,” and continue to try to control legal costs wherever practicable.

“FHFA and Fannie Mae believe that their options are limited in paying current legal fees for former officers and directors, which now amount to almost $100 million,” FHFA’s inspector general, Steve Linick, said in a statement, adding that his office “nonetheless believes that FHFA must continue its efforts to both control and scrutinize these legal expenses now and in the future.”

The key case cited in the report involved a pending case against Fannie Mae in which a trio of former senior executives — former Chief Executive Officer Franklin D. Raines, former Chief Financial Officer J. Timothy Howard, and former Controller Leanne G. Spencer – are accused of engaging in practices that artificially inflated the price of Fannie Mae’s publicly traded stock. Between 2004 and 2011, the report states, Fannie Mae advanced $99.4 million in legal expenses to cover the representation of Raines, Howard, and Spencer in connection with government investigations and lawsuits stemming from accounting irregularities uncovered in 2004. That amount includes $37 million that FHFA has permitted Fannie Mae to advance to the the three former officials since the companies were placed into conservatorship during the financial crisis.

The inspector general’s report comes a day after the FHFA released a plan for beginning to scale back Fannie and Freddie, even as the Obama administration is pressing the taxpayer-backed companies to do more to help homeowners.

The FHFA wants to wind down Fannie and Freddie primarily by increasing fees charged to borrowers who take out mortgages. The agency’s hope is that as the cost of receiving a taxpayer-backed mortgage goes up, more borrowers will turn to private lenders, whose loans do not carry government backing.

But the effort could conflict with measures being pursued by Fannie and Freddie — and the Obama administration — to increase the government’s role in housing. A year ago, the administration released a white paper calling for a gradual shrinking of Fannie and Freddie.

But for much of the past year, the White House has been going in the opposite direction. Administration officials have been urging Fannie and Freddie to take steps to help homeowners in an effort to lift home values, free up cash in the economy and help borrowers avoid foreclosure.

Officials have been encouraging the companies to reduce debts owed by homeowners, for instance, and to make it easier for borrowers to refinance at lower interest rates. Those measures require Fannie and Freddie to take new risks with taxpayer money, and make the housing market more reliant on the government.

The FHFA, which controls the firms in a legal arrangement known as conservatorship, has resisted taking steps that would burden Fannie and Freddie with more taxpayer losses.

“This is clearly one of the challenges that FHFA faces as conservator,” said Edward DeMarco, acting FHFA director. “We’re getting a clear message about wind-down. At the same time, there are continuing to be calls for . . . Fannie and Freddie to do more.”

The companies are essential players in the $10 trillion housing finance market. Operating through the banking system, they connect investors around the world with Americans looking to buy homes. By pledging that taxpayers will make investors whole if borrowers default, Fannie and Freddie are essentially able to guarantee a plentiful supply of funding for mortgages, making it easier for buyers to get affordable home loans.

Fannie and Freddie, together with the Federal Housing Administration, have dominated the housing market during the past four years as banks withdrew sharply from lending during the financial crisis and recession. The private market has not bounced back with the rest of the economy. Policymakers are concerned about the risk to taxpayers presented by the government’s large footprint in the mortgage market. The Obama administration plans to publish more details about overhauling housing finance in the coming months.

Staff writer Zachary A. Goldfarb contributed to this report.