In an extraordinary ruling, a state supreme court judge has ordered the developers of a nearly completed 668-foot block of flats in New York to remove as many as 20 or more floors from the top of the building.

The decision is a major victory for community groups who opposed the project on the grounds that the developers used a zoning loophole to create the tallest building on the Upper West Side of Manhattan. A lawyer representing the project said the developers would appeal the decision.

Justice W Franc Perry ordered that the Department of Buildings revoke the building permit for the tower at 200 Amsterdam Avenue and remove all floors that exceed the zoning limit. Exactly how many floors might need to be deconstructed has yet to be determined, but under one interpretation of the law, the building might have to remove 20 floors or more from the 52-storey tower to conform to the regulation.

“We’re elated,” said Olive Freud, the president of the Committee for Environmentally Sound Development, one of the community groups that brought the suit.

“The developers knew that they were building at their own peril,” said Richard Emery, a lawyer representing the community groups that challenged the project before the foundation was even completed. Mr Emery said this decision sent a warning to other developers who proceed with construction despite pending litigation.

Building of the Year 2020 nominees Show all 25 1 /25 Building of the Year 2020 nominees Building of the Year 2020 nominees building-of-the-year-nominations-13.jpg Fernando Alda Building of the Year 2020 nominees building-of-the-year-nominations-5.jpg Sam Oberter Photography Building of the Year 2020 nominees building-of-the-year-nominations-18.jpg Juneyoung Lim Building of the Year 2020 nominees building-of-the-year-nominations-4.jpg Cyrille Weiner Building of the Year 2020 nominees building-of-the-year-nominations-24.jpg Namgoong sun Building of the Year 2020 nominees building-of-the-year-nominations-14.jpg Robert Hoesl Building of the Year 2020 nominees building-of-the-year-nominations-23.jpg Georg Aerni Building of the Year 2020 nominees building-of-the-year-nominations-22.jpg Takumi Ota Building of the Year 2020 nominees building-of-the-year-nominations-17.jpg Archexist Building of the Year 2020 nominees building-of-the-year-nominations-16.jpg Terry Wier Building of the Year 2020 nominees building-of-the-year-nominations-12.jpg Chao Zhang Building of the Year 2020 nominees building-of-the-year-nominations-15.jpg Simone Bossi Building of the Year 2020 nominees building-of-the-year-nominations-9.jpg Hiroshi Mizusaki Building of the Year 2020 nominees building-of-the-year-nominations-8.jpg Feng Shao Building of the Year 2020 nominees building-of-the-year-nominations-1.jpg Quang Dam Building of the Year 2020 nominees building-of-the-year-nominations-25.jpg Studio Millspace Building of the Year 2020 nominees building-of-the-year-nominations-6.jpg Hertha Hurnaus Building of the Year 2020 nominees building-of-the-year-nominations-21.jpg Picture 020 Rory Gardiner Building of the Year 2020 nominees building-of-the-year-nominations-11.jpg Edouard Sanville Building of the Year 2020 nominees building-of-the-year-nominations-19.jpg FangFang Tian Building of the Year 2020 nominees building-of-the-year-nominations-10.jpg Deed Studio Building of the Year 2020 nominees building-of-the-year-nominations-7.jpg Dhrupad Shukla Building of the Year 2020 nominees building-of-the-year-nominations-3.jpg Edmund Sumner Building of the Year 2020 nominees building-of-the-year-nominations-2.jpg Koichi Torimura Building of the Year 2020 nominees building-of-the-year-nominations-20.jpg Paul Riddle

The question at the heart of the suit was whether the developers had abused zoning rules to justify the project’s size.

It is common for developers to purchase the unused development rights of adjacent buildings to add height and bulk to their project. But in this case opponents of the project argued that the developers, SJP Properties and Mitsui Fudosan America, created a “gerrymandered”, highly unusual 39-sided zoning lot to take advantage of the development rights from a number of tenuously connected lots. Without this technique, the tower might have been little more than 20 storeys tall, instead of the nearly finished 52-storey tower that now stands.

The decision also sets an important precedent, said Elizabeth Goldstein, president of the Municipal Art Society of New York, one of the advocacy groups that brought the suit against the project.

“The way this zoning lot was constructed has been invalidated, and that is extremely important,” Ms Goldstein said, adding that the decision would deter other developers from attempting similar strategies.

Scott Mollen, a lawyer with the firm Herrick Feinstein, which is representing the project, said the ruling contradicted earlier decisions from the Department of Buildings and the Board of Standards and Appeals that were based on a long-established zoning interpretation. SJP, one of the developers, said they would “appeal this decision vigorously”.

What comes next is unclear. While further litigation would effectively postpone any disassembly of the tower, sales at the luxury block would also be held up. Marketing is well underway for the 112 luxury apartments, and the most lucrative units are on the top floors — including a $21m (£16m) penthouse, which would likely be removed if the decision stands.