A New York Supreme Court judge has ruled that the developers of a contested luxury condo building on the Upper West Side must remove an undetermined number of floors from the nearly completed project.

Justice W. Franc Perry issued the extraordinary decision on Thursday, ordering the Department of Buildings to revoke the building permit for 200 Amsterdam Avenue — poised to be the neighborhood's tallest building.

Perry sided with community activists who'd brought suit against the developers, SJP Properties and Mitsui Fudosan, over the 670-foot-tall luxury tower. He found the city erred in issuing the permit for construction, which opponents said was based on a 39-sided "gerrymandered lot" that abused zoning protocols.

The judge also took the highly unusual step of ordering the developer to demolish all floors of the tower that defy the stated zoning limit. It's unclear how many stories will be lopped off — potentially 20 or more of the 55-story building.

The developers have vowed to appeal the ruling, which “defies more than 40 years of precedent in the city’s zoning laws,” according to their attorney, Scott Mollen. He added that the top floors of the new tower had already been sold and that it could be dangerous to remove them. The building's two duplex penthouses were listed for $40 million each.

Opponents of the project, meanwhile, allege the building is out of scale with the neighborhood, and that the developer refused to halt construction even amid an ongoing legal battle. Congressman Jerry Nadler, Manhattan Borough President Gale Brewer, and several other elected officials plan to celebrate the ruling with a rally at the construction site on Monday.

"This groundbreaking decision averts a dangerous precedent that would have ultimately affected every corner of the city,” said Elizabeth Goldstein, president of the Municipal Art Society of New York (MAS), which led the lawsuit. “The directive to partially demolish the building is appropriate given the willingness of the developer to ignore every sign that their project was inappropriately scaled for the neighborhood and based on a radical and wildly inaccurate interpretation of the Zoning Resolution.”

A spokesperson for the city's law department said they were reviewing the decision.