WASHINGTON — Mortgage giant Fannie Mae earned $8.7 billion in the July through September period, its seventh straight profitable quarter. The government-controlled company will have nearly repaid in full its taxpayer bailout of five years ago, after paying its third-quarter dividend.

Fannie said Thursday its earnings were boosted by the rise in home prices during the quarter, which enabled it to reduce its reserves set aside for losses on mortgages.

The earnings for the latest period compared with net income of $1.8 billion in the third quarter of 2012.

Washington-based Fannie said it will pay a dividend of $8.6 billion to the U.S. Treasury next month, bringing its payments to about $114 billion. Fannie received about $116 billion from taxpayers when the government rescued it and smaller sibling Freddie Mac during the financial crisis, after they incurred massive losses on risky mortgages. Together they received aid totaling about $187 billion.

Fannie said Thursday that it expects to remain profitable “for the foreseeable future.”

The housing recovery that began last year has made Fannie and sibling Freddie Mac profitable again. Their repayments of the government loans have helped make this year’s federal budget deficit the smallest in five years.

Fannie and Freddie own or guarantee about half of all U.S. mortgages, worth about $5 trillion. Along with other federal agencies, they back roughly 90 percent of new mortgages.

The two companies don’t directly make loans to borrowers. They buy mortgages from lenders, package them as bonds, guarantee them against default and sell them to investors. That helps make loans available.

President Barack Obama has proposed a broad overhaul of the U.S. mortgage finance system — including winding down Fannie and Freddie.

The goal is to replace them with a system that would put the private sector, not the government, primarily at risk for the loans. The government would still be involved, both in oversight and as a last-resort loan guarantor. Obama also wants a guarantee that private lenders will make sure homeowners have access to 30-year fixed mortgages.

A fix to the housing finance system is unlikely to be easy, however. The Obama plan is in line with bipartisan Senate legislation. But most House Republicans want the market almost completely privatized, while many Democrats insist on government having a larger role.