When a judge overturned the Inwood rezoning last week, developers were shocked. So were the activists who opposed the rezoning.

During an extended long-shot campaign, a coalition of community organizations, under the banner Northern Manhattan is Not for Sale or “NMN4$,” staged raucous protests and packed the courtroom to voice their discontent with the city’s plan. The rezoning was approved in August and few expected the lawsuit to get traction.

“I didn’t think the court would take something like this so seriously,” said Cheryl Pahaham, co-chair of Inwood Legal Action.

Lawsuits challenging rezonings are seldom successful. The coalition of community groups was consumed with translating witness testimonies, gathering research and organizing fundraisers to pay the attorney’s fees — but not all of them agreed that was the best course.

“Not only was it a waste of energy strategically, but it was also a bad organizing tactic, because it channels energy into experts and makes people not feel ownership of the neighborhood,” said one organizer, speaking on condition of anonymity. “But now that it worked, we all are happy that it happened.”

Lena Melendez, an organizer with Inwood Legal Action, acknowledged that within the coalition of groups, there were often disagreements.

“When one group benefits off of the misery of another, it’s sort of riveting for the judge,” said Melendez. “I think she was sympathetic to that, and we got a favorable ruling.”

City Council member Ydanis Rodríguez, who represents Inwood and is running for Congress in a Bronx district bordering the neighborhood, supported the city’s proposed rezoning despite opponents’ affordability concerns.

In a statement, Rodriguez said the court decision “is about procedure,” and highlighted many community meetings he held before the new zoning was approved. “The deal we obtained from the city is the best rezoning deal to date and it reflects the priorities of the many community stakeholders in our district,” he said.

Rodriguez’s district office was occupied by activists last year, who were furious after the City Council — following his lead — voted for the rezoning.

The rezoning now faces months of uncertainty: The city will appeal the judge’s decision, and whoever loses in the Appellate Division will likely appeal to the state’s high court. Organizers who opposed the city’s plan are hoping to take advantage of the extra time to drum up support for an alternative community plan, which demands 100 percent affordable housing.

“The organizing path for us is to make noise around this plan,” said Avi Garelick, of the DSA. “Instead of the city dragging its feet, they should come to the table with us.”

The de Blasio administration will try its luck in court first, where the mayor said Friday that he expects to prevail.

The administration announced in 2014 that it would spend $8 billion subsidizing units for low-income households, primarily in neighborhoods where the market is not strong enough for market-rate units to subsidize deeply discounted apartments.

But Inwood, with good mass transit and proximity to Manhattan’s job centers, is not one of those neighborhoods.

Indeed, Mayor Bill de Blasio saw it as ideal for his housing plan, the premise of which is to upzone areas to trigger mandatory inclusionary housing. MIH requires housing development be mixed-income, with high-rent units essentially funding low-rent ones.

Still, he had to kick in $200 million worth of community investments to secure Rodriguez’s vote. Some Inwood rezoning opponents may be betting there is more where that came from.