Sales of previously owned U.S. homes notched their fastest pace in nearly two years in July, an industry survey showed on Friday, the strongest sign yet that housing was pulling out of a three-year slump.

The National Association of Realtors said that sales jumped 7.2 percent to an annual rate of 5.24 million units, the highest since August 2007, beating market expectations for a 5 million unit pace. Sales were at a 4.89 million pace in June.

July's percentage increase was the largest monthly gain since the series started in 1999 and marked the fourth straight monthly advance. The last time sales rose for four consecutive months was in June 2004, the NAR said.

U.S. stock indexes rallied on the data, while Treasury debt prices extended losses as investors viewed the report as another indication that the recession that started in 2007 was close to or ending.

Existing home sales data show that we are moving in the right direction, said Kevin Flanagan, fixed income strategist for Global Wealth Management at Morgan Stanley in Purchase, New York.

Compared to July last year, sales rose 5.0 percent. The improvement in sales in July was broad based with single-family home sales rising 6.5 percent to annual rate of 4.61 million units and multifamily dwellings surging 12.5 percent to a 630,000 unit rate.

The housing market has decisively turned for the better. We are bouncing back, NAR chief economist Lawrence Yun told reporters.

Housing data continue to indicate the sector is starting to turn after a three-year slump, but high unemployment threatens the budding recovery as many homeowners continue to lose their properties.

A report from the Mortgage Bankers Association on Thursday showed late homeloan payments jumped to a record high in the second quarter, with almost one in eight homeowners delinquent or in the process of foreclosure.

The inventory of existing homes for sale in July rose 7.3 percent to 4.09 million units from the previous month, and represented a 9.4 months' supply at the current sales pace, unchanged from June, the NAR said.

The national median home price was $178,400 in July, down 15.1 percent from the same period last year, weighed down by distressed sales as they typically sell for 15 to 20 percent less than traditional homes.

(Reporting by Lucia Mutikani)