A federal judge has upheld a New York state law that largely bans immigration arrests at state and local courthouses, dismissing a Trump administration’s lawsuit challenging the rule.

The law, called the “Protect Our Courts Act,” was passed in 2020, during President Donald Trump’s first term in office. It bans law enforcement officers from making civil arrests of people attending, leaving or going to court proceedings as a parties or witnesses to cases, unless judicial warrants or orders authorize the arrests. The law also protects family and household members of people attending court proceedings.

The dismissal marks a defeat in the Trump administration’s efforts to limit so-called sanctuary laws that limit ICE enforcement and cooperation between ICE and local governments. It comes after a federal judge in Illinois in July dismissed another Trump administration lawsuit challenging the constitutionality of so-called sanctuary measures in the state.

But the Protect Our Courts Act does not affect federal courts, including immigration courts such as the one at 26 Federal Plaza, where many immigrants in New York City have been detained following immigration court hearings.

Judge Mae A. D’Agostino's 41-page ruling also comes after Trump administration officials’ promises to “flood the zone” with ICE enforcement in New York City. Last month, federal officers arrested nine West African men, largely street vendors, in a raid that the Department of Homeland Security has said was a crackdown on the sale of counterfeit merchandise.

Spokespeople for the Department of Justice did not immediately respond to a request for comment.

New York Attorney General Letitia James and Gov. Kathy Hochul applauded the judge’s decision.

“Everyone deserves to seek justice without fear,” James said in a statement. “This ruling ensures that anyone can use New York’s state courts without being targeted by federal authorities.”

In 2017, at the start of the first Trump administration, ICE departed from its long-standing policy that generally prohibited arrests at courthouses. ICE arrests at New York state courthouses increased by 1,200% between 2017 and 2020, according to D’Agostino's ruling.

Lawyers for the federal government have argued that the Protect Our Courts Act impedes federal immigration enforcement in New York state by limiting where ICE officers can operate, in violation of the supremacy clause of the Constitution, which says federal law takes precedence over conflicting state laws. ICE has also argued that arrests at courthouses are often safer, because people are screened for weapons before entering.

However, proponents of the Protect our Courts Act say the law is crucial to ensure immigrant victims and witnesses will continue coming to court, including domestic violence survivors and tenants with abusive landlords. Immigration and legal advocates also say that ICE arrests at courthouses delay court operations in an already backlogged court system.

In her ruling, D’Agostino also upheld two executive orders mentioned in the lawsuit and signed by then-Gov. Andrew Cuomo in 2017 and 2018, which further limit ICE operations in the state.

Executive Order 170, signed in September 2017, generally prohibits state employees from disclosing information to ICE to assist with immigration enforcement. Cuomo amended that executive order in April 2018 to include a section which prohibits ICE from arresting people in state-run buildings without a judicial warrant or order.

James has also asked a federal judge to dismiss a separate lawsuit filed by the Trump administration, challenging the constitutionality of a different New York state law that allows immigrants without legal status to receive a driver's license and prevents ICE from accessing the state's extensive database of motor vehicle records.

The Trump administration has also filed a lawsuit challenging New York City's sanctuary laws, a case that remains pending.