After years of delays, top city officials have reached an agreement to overhaul the way the New York City Police Department operates in schools for the first time since Mayor Rudy Giuliani was in office.

The new agreement, set to be announced Thursday, is meant to limit the situations in which police officials can send students into the criminal justice system for relatively low-level offenses. The agreement also discourages school officials from making referrals to the police for minor misbehavior.

The changes mark a major move away from the zero-tolerance policies that dominated the city’s approach to school discipline when the agreement was created. The document — which governs police involvement in school security and formally handed the police department authority over roughly 5,000 school safety agents — was supposed to be updated every four years, but has never been revised.

Among the biggest changes, the new agreement says that police officials should not arrest or summons students “whenever possible” for low-level offenses such as marijuana possession, disorderly conduct, spitting, or graffiti. It also limits school staff from calling school safety agents for infractions like uniform violations, cutting class, lateness, smoking, lying, or gambling — as long as they can be addressed “safely.”

Some advocates said the new agreement is a big step in dialing back police presence in schools. Though arrests and summonses have fallen in recent years, the vast majority are issued to black and Hispanic students.

“There’s still a lot of discretion baked in, but what you’re seeing is the school safety division give up their authority to arrest in every situation, and that’s big coming from the NYPD,” said Johanna Miller, an education policy expert at the New York Civil Liberties Union who participated on a mayoral task force to revise the agreement.

“This [agreement] addresses some of the biggest contributors to arrests in schools and should reduce them dramatically,” she added.

In the past, students could also be arrested in school for minor offenses that occurred off school grounds, a practice that advocates have criticized as needlessly disruptive to schools and students. In a separate change, officials said the police patrol guide has been revised to “strictly limit” those arrests to felonies, sex offenses, and “crimes where there is an immediate risk of escape or where the perpetrator is apprehended in hot pursuit.”

The agreement between the police and education departments has been controversial since it was first inked in 1998, with some city officials saying the presence of police officials made student misbehavior more likely to end in arrests. The process of updating it has been long and fraught.

In 2016, a mayoral task force proposed an overhaul to the agreement and negotiated a series of changes that would have limited police involvement on issues such as cutting class, smoking cigarettes, and certain instances of insubordination, participants said.

Even though top education and police officials participated in the process and seemed amenable to changes, those proposed compromises largely disappeared when the city presented a new draft agreement, according to people who were present during the meetings. Some task force members said education and police department lawyers, who had not participated in the group’s discussions, played a role in stripping the draft agreement of the most important reforms.

Meanwhile, members of the task force often went long stretches without substantive updates, and a final agreement was repeatedly delayed. Schools Chancellor Richard Carranza even expressed reservations about a draft agreement this March. “I was not satisfied with what I saw was developing,” he said. “There was a lot in that [agreement] that was very much law-enforcement centric. We’ve been pushing back and we’ve actually been having great conversations with NYPD.”

Miller, who had been frustrated that their initial recommendations were gutted, said the final version “reflects some of the language the leadership team worked on together, so I’m really pleased to see that.”

In addition to reducing arrests, summonses, and police referrals, the new agreement calls for expanded training on de-escalation and conflict resolution among school safety agents and traditional patrol officers.

“The updated MOU and Patrol Guide reflect our values and demonstrate a clear commitment to safe and supportive learning environments for all students and staff,” Carranza said in a statement. “Taken together with our investments in restorative justice, and social-emotional learning, we’re ensuring each of our school communities has a foundation of positive relationships, respect, and support.”