The government-controlled company also said Tuesday that it paid dividends of $11.6 billion to the U.S. Treasury in 2012. Fannie says it expects to remain profitable "for the foreseeable future."
The company did not seek any federal assistance in 2012. That followed a year in which the company reported a net loss of $16.9 billion and requested $25.9 billion in federal assistance.
Taxpayers spent $188 billion to rescue Fannie and smaller sibling Freddie Mac from their exposure to risky loans that triggered the 2008 financial crisis. Fannie received $116 billion and has paid back $35.6 billion.
Freddie received $72 billion and has paid back nearly $24 billion.
The recovery of the housing market has enabled both companies to become profitable again. Freddie has posted positive net earnings for the past five quarters.
"Our financial results improved significantly in 2012 and we expect our earnings to remain strong over the next few years," Timothy Mayopoulos, Fannie's president and CEO, said in a statement.
Fannie earned $7.6 billion in the October-December quarter, a quarterly record for the company. A legal settlement with Bank of America Corp. provided $1.3 billion of the gain. Fannie paid the Treasury a quarterly dividend of $2.9 billion.
Under a federal policy adopted last summer, Fannie and Freddie must turn over their quarterly profits to the government.
The fourth-quarter earnings compared with a net loss of $2.4 billion in the final quarter of 2011.
Fannie and Freddie together own or guarantee about half of all U.S. mortgages, or nearly 31 million home loans. Those loans are worth more than $5 trillion. Along with other federal agencies, they back roughly 90 percent of new mortgages.