NEW YORK, FEB. 9 -- What goes up must come down -- even, apparently, in high-rise New York.

Surprising a city in which builders routinely erect towering skyscrapers, the state's highest court today ordered a developer to dismantle the top 12 stories of a 31-story apartment building.

The New York State Court of Appeals ruled that the $7.2 million Park Avenue high-rise at East 96th Street violates a zoning law setting height limits on one of Manhattan's most affluent thoroughfares.

The city originally gave the developer, Parkview Associates, permission to build 31 stories. But two years ago, after construction was well under way, a community group on the Upper East Side warned the city that the building appeared to be too tall.

After city officials reread the zoning map, acknowledged their error and revoked the developer's permit, Parkview Associates went to court.

"They continued to complete the upper stories," Buildings Commissioner Charles Smith said, "and now we see that they did so at their own peril."

Smith said today that he has ordered the architects to modify the building: "They are required to file engineering documents on how they plan to remove the top 12 stories and how they are going to protect the adjacent buildings while the demolition is going on."

Jefferey Braun, an attorney representing the developer, said his client was the victim of foul-ups by the city. As a last resort, Parkview Associates has asked a city appeals board for a hardship exemption.

"The actual cost of hiring someone to take down the stories is not the issue," Braun said. If the developer can build only 19 stories instead of 31, reducing the number of apartments by more than one-third, "it represents a loss on the property investment of nearly $10 million," Braun said.

The appeals court said that although the city erred in issuing the initial permit, the company could have prevented the mistake by using "reasonable diligence" in researching the zoning requirements.

The city has been criticized for allowing developers to build huge skyscrapers in exchange for cash payments and other tradeoffs. In this case, the city joined forces with community groups, which often try to use arcane zoning regulations to limit development and preserve the character of their neighborhoods.

Constance Adamec, chairman of the local community board, said a 10-year-old zoning law limits the height of buildings along Park Avenue to 210 feet "to control the . . . shadows they cast on Central Park" two blocks west.