Mayor Bill de Blasio signed legislation to sharply limit the city’s cooperation with detainers issued by Immigration and Customs Enforcement—and to boot that federal agency from Rikers Island.

“What these bills do is they protect the rights of undocumented immigrants, of visa holders, and legal permanent residents alike, all of whom have suffered under the previous approach, and ultimately prevent families from being torn apart,” Mr. de Blasio said at a Queens press conference.

ICE issues detainers to local law enforcement agencies—like the NYPD or Department of Correction—asking them to hold an individual even after his or her cases have been resolved, often without a warrant. The detainers allow the person to be picked up by federal immigration authorities, who often hold the person for months before initiating deportation proceedings.

The new laws being signed today will only allow the NYPD or Corrections to honor a detainer if it comes with a federal warrant—and even then, only if the person in question has been convicted of a violent or serious felony in the last five years, or is a possible match on the terrorist watch list.

While some opposed to the legislation have argued it will compromise safety, Mr. de Blasio and advocates have sought to argue the opposite: undocumented immigrants will be more likely to approach police for help or with tips if they do not fear deportation, they’ve said.

“When people understand in all cases police are here to protect, and will not be part of deporting, it will encourage people to come forward,” Mr. de Blasio said.

To illustrate the detainer policy—which can be something of a wonky legal matter—Mr. de Blasio told the story of a man named Carlos Rodriguez, a Dominican immigrant who he said was arrested for trespassing in a building near his home. Mr. Rodriguez was simply visiting a friend and the charges were promptly dropped.

“He wasn’t released, because the city at that time honored ICE’s detainer request and held him. There was no warrant for Carlos. He had no criminal record. He had done nothing wrong. But he was being held,” Mr. de Blasio said.

Mr. Rodriguez remained in federal custody for eight months before being freed by lawyers, but is still facing deportation.

According to the mayor’s office, the new policy could bring the percentage of detainers honored to “virtually zero” and would prevent between 2,000 and 3,000 New Yorkers per year being held within the city for the purpose of being place into deportation proceedings.

The legislation signed today was introduced by Speaker Melissa Mark-Viverito, along with several co-sponsors, and was passed by the Council last month. Ms. Mark-Viverito argued it is “unfair and it is un-American” to hold people for a civil immigration detainer without a warrant or a showing of probable cause that a crime has been committed.

“New York City has no business expending scarce resources assisting in the enforcement of broken immigration laws That is not the role of our police officers. That is not the role of our corrections officers,” she said.

For not the first time, Mr. de Blasio knocked Washington for failing to act on comprehensive immigration reform—a critique he also offered up when the city created its own municipal identification cards in part to aid undocumented immigrants.

“You look at cities around the country and some states even, they’re already acting in the absence of federal leadership. And I think what happens, I think our nation’s history speaks to this, is when—one city acts, then another city acts, then a state acts, then another state acts—slowly but surely it becomes national policy. It becomes irresistible,” Mr. de Blasio said.

Both the speaker and the mayor praised President Barack Obama for pledging to take action on immigration through an executive order—but said more needs to be done.

“We know that we need comprehensive legislation passed by the House, passed by the Senate,” Ms. Mark-Viverito said. “The president is trying to do what he can but I don’t have much faith unfortunately in what these elections have brought, so in that vein we as municipalities are being asked to step up to the plate.”