That was well above analysts' expectations and marked the fastest pace of sales since November 2009, when a home buyer tax credit was expiring.
(Click here to track the U.S. stock market following this economic report.)
After being devastated by a financial crisis and the 2007-09 recession, the U.S. home market appeared to turn a corner early last year, helped by steady job creation and extremely low interest rates.
"The current housing market recovery is on a solid footing," said Lawrence Yun, chief economist at the NAR.
(Read more: Mortgage apps take new hit as surging rates bite)
Last month, home buyers appeared undeterred by a recent spike in borrowing rates. Indeed, Yun suggested some home buyers might be rushing to make purchases now to avoid further rate increases that are widely expected.
Lenders have increased rates on expectations the U.S. economy will shift into higher gear and that the U.S. Federal Reserve will tighten monetary policy.
Since early May, mortgage rates have risen more than a percentage point for 30-year loans. Last week, the average rate for a 30-year mortgage rose 12 basis points to 4.68 percent, the Mortgage Bankers Association said in a report on Wednesday. .
Economists polled by Reuters had expected sales to increase to a 5.15 million unit pace in July. Sales rose in all four major regions in the country.
The housing market recovery, marked by a surge in prices and dwindling inventories, is helping to shore up the economy by bolstering household finances and supporting consumer spending.
The median price for a previously owned home soared 13.7 percent from a year ago to $213,500. The inventory of unsold homes on the market rose 5.6 percent, leaving the months' supply unchanged at 5.1.
Other details of the report were also encouraging. Distressed properties - which can depress prices because they typically sell at deep discounts - accounted for only 15 percent of sales last month.
That matched June's reading, which was the lowest since the realtors group started monitoring them in October 2008.