Home sales in the Baltimore region shrank for the first time in nearly two years last month as prices inched up, inventory shrank and deals involving distressed properties, including foreclosures, plummeted.

The number of home sales in the metro area dropped to 3,561 in July, nearly 2?percent fewer than in July 2015, the research firm ShowingTime RBI reported Wednesday.

The decline ended a 23-month streak of increasing year-over-year closings. The analysis was based on listing activity in Baltimore and the five surrounding counties from the MRIS multiple listing service.

Sales of distressed properties, which fell by more than 25 percent, helped drive the decline. Excluding them, sales increased nearly 4 percent year-over-year in July.

The drop in closed sales was the sharpest June-to-July contraction since 2010. But given the shrinking number of distressed deals, it could be a sign of market improvement, said Bonnie Casper, president of the Maryland Association of Realtors.

“It shows you that the inventory in fact is diminishing for the bank-mediated ones,” she said. “That's not a bad thing; that's a good thing.”

The median price for a home in Baltimore and the five surrounding counties was $267,500 in July, ShowingTime RBI reported. That is up about 3 percent from last year, but 6 percent less than the July peak set in 2007.

For nondistressed properties, the median price rose 1.2 percent, to $293,425.

Though supply has tightened — active listings shrank 10.5 percent from July 2015 — industry professionals say the market remains largely in balance.

“We're in a good, steady market right now,” said Georgiana Tyler, an agent for Coldwell Banker Residential Brokerage in Roland Park.

Baltimore, the least expensive jurisdiction studied, reported the biggest price gains, with the median rising 16 percent year-over-year to nearly $157,000 as foreclosures fell.

Anne Arundel County followed, with the median price increasing 1.3 percent, to $323,000.

In Baltimore County, the median increased 1 percent to $227,000. Prices fell about 1 percent in Carroll and Harford counties.

Howard County was still the most expensive of Baltimore's suburban counties, even after the median price fell about 6?percent from July 2015 to $415,000.

Buyers are doing extensive research before a purchase, Tyler said, which keeps price growth in check. That in turn could be keeping some sellers on the sidelines as they wait for stronger appreciation.

Broad global uncertainty, fueled by terrorist attacks, Britain's vote to leave the European Union and violence in the Middle East, is also making buyers and sellers more cautious, Tyler said.

“There's things that happen in the world, as well as in this country, that just have a very, very subtle way of saying to everybody, ‘Let's be reasonable, let's keep moving forward, let's not do anything rash, let's not do anything crazy,'?” she said.

With the regional economy expected to continue to improve, sales activity and pricing should grow at a modest pace for the next few years, said Dan Fulton, a senior vice president at John Burns Real Estate Consulting LLC.

“We see employment has really been strong in the Baltimore metro area, especially the sort of employment that drives housing growth,” Fulton said. “We have a good couple years to go, maybe three years to go, before we have to even think about is there a downturn.”

nsherman@baltsun.com