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.
Fannie said Wednesday that it paid a dividend of $2.9 billion to the Treasury Department and sought no additional aid.
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.
On Tuesday, McLean, Va.-based Freddie Mac 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. Along with several federal agencies, they backed nearly 90 percent of new mortgages over the past year.
The government rescued the two companies during the financial crisis after they incurred massive losses on risky mortgages. 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.
Anthony Sanders, a real estate finance professor at George Mason University, said stable prices have reduced Fannie and Freddie's losses on mortgages. But he doubts either Freddie Mac or Fannie Mae could ever repay their full debt to the taxpayers.
The companies are so deep in debt to the government that they'd need several decades of profits to fully repay, Sanders says.