A scant supply of homes drove up Long Island housing prices last month.

Nassau County homes sold for a median price of $503,500 in January, up 6 percent from a year before, the Multiple Listing Service reported Thursday. In Suffolk County, the median price increased by 5.9 percent, to $359,000.

The number of listings fell year-over-year by 14 percent in Suffolk, to 5,693, and 3 percent in Nassau, to 4,059. It would take less than five months to sell all the homes listed for sale, less than the six- to eight-month supply that brokers call a balanced market.

The market is especially hot for well-maintained, moderately priced homes — about $350,000 to $450,000 in Suffolk and $400,000 to $600,000 in Nassau, brokers said.

“I can’t even tell you how crazy this market is, we have to be ready to go at a moment’s notice,” said Debbie Carpluk, a real estate agent with Keller Williams Elite in Massapequa Park and Islip.

When new listings come on the market, she said, “we’re getting swarmed, there’s multiple offers within one to three days and prices are going over asking.”

Rising prices are actually preventing some homeowners from listing their properties, because they can’t find another home on Long Island that they’d like to move to, said Nick Sakalis, a real estate agent with Coldwell Banker Residential Brokerage in Syosset.

Get the Biz Briefing newsletter!

“The sellers that are benefiting the most are the ones that are moving out of state,” he said.

In Nassau, there were 906 closed home sales last month, down 5.5 percent compared with the previous year. In more affordable Suffolk, home buying activity rose by 5.5 percent annually, with 1,183 homes changing hands.

In an indication that it could be a busy spring for the home sales market, the number of contract signings increased by about 8 percent year-over-year in both counties.

Many buyers are eager to complete their purchase before interest rates rise further, Sakalis said.

The average rate for a 30-year mortgage was 4.38 percent this week, up 0.23 percentage point from a year earlier and the highest level since April 2014, mortgage giant Freddie Mac reported.

So far, higher borrowing costs haven’t deterred many buyers, but that could change, brokers said.

“The magic number is five” percent, Sakalis said. “Once we get past five, that’s going to cut down on a lot of the buying power that these buyers have.”