The City Council on Tuesday passed nearly 40 bills — including contentious legislation to restrict how NYPD cops handle encounters with the public — in a divisive final meeting under its current leader.

Lawmakers approved legislation forcing private employers to grant workers in certain circumstances two temporary schedule changes per year, requiring the city to consider changing forms to reflect gender-neutral pronouns like “ze,” lowering permissible noise levels at construction sites, criminalizing disseminating sexually explicit images without the depicted person’s permission, and dozens of other bills.

The police bills were the most high-profile to be approved — one to force cops in certain nonemergency encounters to give name, rank and command, explain the reason for the stop and hand out business cards when no one is arrested or issued a summons. Another mandates that cops record explicit consent, either on audio or in writing, before searching a person absent a legal basis.

The first bill passed 27 to 20, with three abstaining. It passed despite the near uniform opposition by police accountability groups, lawyers for the poor, and a coalition of families whose loved ones had been killed over the years in encounters with the NYPD. The foes said the bill — which was watered down from a prior version — created loopholes the NYPD could exploit, would sow confusion among people being stopped, and omitted many types of encounters.

The lead sponsor, Councilman Ritchie Torres, a Bronx Democrat, had been criticized for what the groups said was deviating too far from the bill’s initial breadth, which included encounters like car stops. He in turn said it’s a start and far better than the status quo.

“Progress in the present does not foreclose the possibility of even more progress in the future,” he said.

Both bills, part of what was called the Right to Know Act, were opposed by the Patrolmen’s Benevolent Association, as was the search bill, which passed 38 to 12. The union argues the legislation would hamper policing.

Torres said a compromise was preferable because he didn’t want a revolt orchestrated by the police union.

Tuesday’s hearing exposed a rare public debate in a council in which not a single bill had been defeated under the four-year tenure of its leader, Melissa Mark-Viverito, a Manhattan Democrat.

As Councilman Jumaane D. Williams, a Brooklyn Democrat, inveighed against the bill as an improper concession to the NYPD and its supporters, Mark-Viverito signaled that his time was over, and his microphone was cut. Williams called the hearing “a sham” and “a shame.”

The legislation capped four years under Mark-Viverito’s speakership that pushed the passage of nearly 700 bills.

“Oh, my God,” Mark-Viverito said in a farewell that ended with her near tears. “It’s incredible.”

Eight council incumbents are vying to replace her.