A federal judge on Thursday rejected the Trump administration’s lawsuit against New York City’s sanctuary laws, ruling that the U.S. government can’t compel police officials and other city agencies to help enforce civil immigration laws.

The dismissal was the latest defeat for President Trump as he attempts to force cities and states to work with the Immigration and Customs Enforcement agency’s mass deportation campaign.

Across the United States, federal judges have spurned the administration’s legal challenges to sanctuary laws in nearly a dozen localities led by Democrats, including Boston, Chicago, Los Angeles, Colorado and Minnesota.

“Because much has already been written about these issues with which this court agrees, this decision will be relatively brief,” Judge Ramón E. Reyes Jr., a judge in U.S. District Court in Brooklyn, wrote in a footnote to his 25-page ruling.

Judge Reyes, who was appointed in 2023 by President Joseph R. Biden Jr., said that the federal government lacked standing and that the Constitution protected cities and states from being forced into spending their own resources to enforce immigration laws, which are the purview of the federal government.

Mayor Zohran Mamdani, a Democrat, celebrated the ruling in a statement, saying that the judge had made it clear that the federal government “cannot commandeer our city workers to do its bidding.”