Ally Financial Inc, the lender formerly known as GMAC, on Monday said it agreed to pay $462 million to Fannie Mae to avoid having to repurchase poorly underwritten mortgages sold to the housing finance giant.

Ally, which is majority-owned by U.S. taxpayers, said the agreement releases its Residential Capital LLC mortgage unit from any liability related to bad underwriting on $292 billion worth of loans sold to Fannie Mae, itself about 80 percent owned by the government.

Residential Capital owns GMAC Mortgage and Ditech Funding.

Ally, which is expected to go public next year, announced a smaller settlement with Freddie Mac in March. Resolving questions about its potential liability could help Ally attract investors.

The lender, which is 56 percent owned by the U.S. government, said the agreements reduce the risk in its mortgage operations going forward.

At the start of 2010, we set a goal to substantially reduce the risk in our mortgage operation, and during the last twelve months, we have successfully completed a series of steps toward that objective and are largely complete, said Michael Carpenter, chief executive of Ally.

In addition to questions about the way it made loans during the housing boom, the company's mortgage foreclosure process has come under fire after an employee admitted to signing thousands of foreclosure-related affidavits without properly reviewing them.

Ally found that it must improve its processes, but said it has found no evidence of improper foreclosures.

The Treasury Department, which has pumped more than $17 billion into Ally, declined to comment, as did Fannie Mae's regulator, the Federal Housing Finance Agency.