WASHINGTON — Government-controlled mortgage companies Fannie Mae and Freddie Mac posted profits for the April-June period as the U.S. housing market continued to recover.

Gains in recent years have enabled them to fully repay their government aid after being rescued during the financial crisis in 2008.

Fannie Mae reported Thursday that it earned $3.7 billion in the second quarter. Washington-based Fannie will pay a dividend of $3.7 billion to the U.S. Treasury next month.

Freddie Mac posted net income of $1.4 billion for the latest quarter. Freddie, based in McLean, Virginia, will pay a dividend of $1.9 billion to the government.