The New York City Council passed sweeping changes to the zoning code on Tuesday, compelling private developers to build low-cost rental units and handing Mayor Bill de Blasio a victory on the centerpiece of his efforts to blunt neighborhood gentrification.

The passage of the proposals capped more than two years of behind-the-scenes planning and organizing by the de Blasio administration, which developed a coalition of unions, business organizations, developers and groups representing older residents while wooing skeptical members of the Council.

In the end, the mayor’s plan, which changes zoning requirements across the city, survived opposition from community boards and building trades unions, as well as from New Yorkers concerned that the changes would encourage the very transformation of low-income areas they were meant to head off.