NEW Yorkers may be feeling smug: While real-estate markets are stumbling in much of the nation, housing prices in the five boroughs have stayed strong. Plus, the stock market has bounced back, temporarily, at least, from its recent decline.

But New York City (and state) shouldn’t count their surplus money yet. If mortgage-industry woes worsen, the concentrated fallout likely will be felt most deeply in New York – hurting Wall Street, tax revenues and perhaps even the city housing market.

New York’s stock exchanges may have been losing out to European competitors recently, but Gotham has kept its dominance in another bread-and-butter Wall Street sector: debt.

Specifically, Wall Street has reaped billions over the past decade by packaging small pieces of debt – much of it residential mortgages backed by homes sold around the nation – into huge bonds for international investors.

Earlier this year, the report for Mayor Bloomberg on New York’s financial industry noted that this “securitisation” business “has grown by over 20 percent annually in the United States since 1995, almost twice as fast as the corporate-debt market . . . and accounted for over half of revenues from all debt issuance.”

Here’s how it works: A mortgage lender approves a loan to a homeowner. But the company doesn’t keep that mortgage on its books; it sells it, and thousands of other mortgages, via a Wall Street bank. That bank splits up groups of mortgages and packages others together to sell as big bonds to big international investors.

For almost a decade now, European and Asian investors have loved these “residential mortgage-backed securities,” as well as related securities backed by home equity loans, because they paid better than Treasury bonds without seeming to carry much more risk.

To meet that vast demand, Wall Street and mortgage lenders increasingly scraped the bottom of the barrel. Companies awarded loans to people with no money down and spotty work and credit histories. They even loaned to people who couldn’t afford to pay their mortgages each month from day one – granting “pay option” loans that let them pay just some of what was due, and pile the rest up as more debt.

Today, such “subprime” loans make up a sixth of total mortgages, up from less than 5 percent six years ago. But now they’re increasingly in delinquency: At the nation’s biggest mortgage lender, 19 percent of subprime mortgages were in delinquency last year, up from 15 percent the year before. On Friday, Wall Street creditors asked another big lender to stop making new loans.

Why would any bank lend money to someone who couldn’t even pay the loan from day one? The answer is twofold, and portends more woes.

First, international investors just wanted to buy more and more mortgage securities, and lenders had to get them from somewhere.

Second, homebuyers (and lenders) expected the home values to keep rising, year after year – just like tech stocks did in the late 1990s. So buyers could just take the “extra” money out every few years, and use it to pay their mortgages. Everyone conveniently overlooked how the tech bubble collapsed . . .

It’s likely the problems aren’t limited to the bottom-of-the-barrel mortgages; they’ll affect higher-quality mortgages, as well – because, as prices stop rising, more quality “prime” homebuyers will find that they owe more on their mortgages than their homes are worth. In fact, “prime” delinquencies at the biggest lender have nearly doubled in a year, to about 3 percent.

The early fallout from declining home prices and rising mortgage delinquencies is already affecting demand for mortgage-backed securities. As the Wall Street Journal reported Friday, some international investors didn’t really know they had purchased subprime mortgages in their mortgage portfolios; now, they’re worried. In January, the volume of new mortgage-backed securities on Wall Street was below last year’s levels for the first time in five years.

A few big Wall Street firms have said they don’t expect to suffer huge earnings hits because of this fallout. We’ll see.

After all, Wall Street firms don’t benefit only from the fees they make in packaging and selling debt to investors: They make money from mortgage debt in a host of other ways, too. Banks and hedge funds lend money to mortgage lenders; they hold and trade the mortgage-backed bonds themselves ; they create and trade all kinds of “credit derivatives” related to the debt.

And all this business has boomed thanks not only to low interest rates, but also to the expectation that housing prices would continue to rise every year.

The pain may last a long time, too. The tech bubble burst all at once; Wall Street firms moved on relatively quickly. But housing prices just don’t adjust as fast (people live in homes, so they’re harder to bail out of then a tech stock). So the housing bubble could continue to lose its air gradually.

A slow unraveling could mean several painfully lean years, not only for Wall Street firms but for New York City and state budgets, which depend on Wall Street-related tax money for much of their revenue.

And lean bonuses on Wall Street could finally do what declines in the rest of the country’s housing market couldn’t do: hit Gotham’s own housing prices, which are a repository for Wall Street bonuses.

Manhattan co-ops don’t sell apartments to buyers who can’t put any money down, and who can’t afford to pay their mortgages. But they do sell co-ops to buyers who reap their bonuses packaging and selling debt backed by such mortgages.