Fannie Mae earned $2.2 billion from April through June, its second quarterly gain in net income since being taken over by the government during the 2008 financial crisis.
The mortgage giant attributed the increase to improving home prices and fewer foreclosures. And it said Wednesday that it was paying $2.9 billion to the Treasury Department, its second straight quarterly dividend.
Fannie's net income attributable to common shareholders was 37 cents per share in the second quarter. That compares with a net loss of $5.2 billion, or 90 cents per share, in the same period last year.
"We think home prices have stabilized," Fannie President and CEO Timothy Mayopoulos said in an interview on CNBC.
Fannie has reported gains in net income in both quarters this year. It earned $2.7 billion in the January-March quarter and paid a dividend of $2.8 billion to the Treasury.
The company received about $116 billion from the Treasury Department, the most expensive bailout of a single company. It has so far repaid about $26 billion.
Mayopoulos said he believes the company can be profitable going forward, though that doesn't necessarily mean that Fannie will make enough money to pay a dividend each quarter to the Treasury.
"It's going to depend on home prices," Mayopoulos said.
The housing market has started to recover this year after languishing since the bust in 2006 and 2007. Home sales are higher than last year, although they are still below healthy levels. Home prices are rising in many markets, partly because the supply of homes for sale has fallen.
U.S. home prices, including sales of distressed properties, jumped 2.5 percent in June from the same month in 2011, according to a report issued Tuesday by data analytics firm CoreLogic. And the Standard & Poor's/Case-Shiller home price index reported price increases from April to May in all 20 cities tracked by the survey.
Fannie and smaller sibling Freddie Mac were taken over by the government after massive losses on risky mortgages threatened to topple them.
Taxpayers have spent about $170 billion to rescue Fannie and Freddie. It could cost roughly $260 billion more to support the companies through 2014 after subtracting dividend payments, according to the government.
On Tuesday, McLean, Va.-based Freddie reported net income of $1.2 billion for the second quarter and didn't request any additional federal aid for the period. The gain compared with a net loss of $3.76 billion in the same period a year ago.
Fannie and Freddie own or guarantee about half of all U.S. mortgages, or nearly 31 million home loans, which are worth more than $5 trillion. Along with several federal agencies, they backed nearly 90 percent of new mortgages over the past year.
Fannie and Freddie buy home loans from banks and other lenders, package them into bonds with a guarantee against default, and then sell them to investors around the world.