The New York Police Department has agreed to curtail stop-and-frisk tactics in thousands of private apartment buildings under a settlement announced Thursday, ending the last in a series of stop-and-frisk lawsuits that fundamentally changed the city’s approach to fighting street crime.

The settlement addressed police stops in and around buildings whose landlords had asked the police to conduct patrols and arrest trespassers under a city-run program. The agreement prohibits officers from approaching, questioning or detaining people merely because they are inside or around those buildings, and forces officers to apply the same constitutional protections there that they are supposed to apply anywhere in the city.

Some civil rights lawyers have said the practice, under the Trespass Affidavit Program, was an especially poisonous element of the city’s stop-and-frisk efforts because people were questioned or detained steps from their own apartments or those of friends or relatives. The lawyers say officers often stopped and searched people who were hanging out in the lobbies of enrolled buildings, and questioned them about trespassing simply for having walked out of a building.

“What was driving all of that was a general belief by police officers that people who were in or near these buildings could be stopped without anything else,” said Christopher Dunn, associate legal director for the New York Civil Liberties Union and lead counsel in the suit in 2012. “That is at the heart of these new standards, which make it clear police officers cannot do that.”