A federal judge in Chicago has ruled that the Trump administration may not withhold public-safety grants to so-called sanctuary cities. The decision issued Friday is a setback to the administration's efforts to force local jurisdictions to help federal authorities crack down on illegal immigration.

U.S. District Judge Harry Leinenweber ruled that Attorney General Jeff Sessions exceeded his authority by requiring cities to cooperate with federal immigration officials or lose grant money for fighting crime. Sessions wanted local authorities to detain people in this country illegally for 48 hours, so immigration agents could apprehend them, and allow agents into local jails.

The judge issued a temporary nationwide injunction in response to a lawsuit brought by the city of Chicago. The order prevents the Justice Department from withholding grant money until there is a final determination in the lawsuit, which could take months.

At stake was more than $2 million that Chicago and its neighboring jurisdictions receive from the Edward Byrne Memorial Justice Assistance Grants.

Local officials around the country, such as Chicago Mayor Rahm Emanuel, have insisted that by cooperating with federal immigration agents they would jeopardize the hard-won trust of immigrant communities. Leinenweber, in his 41-page ruling, said that the city could suffer "irreparable harm."

"Once such trust is lost, it cannot be repaired through an award of money damages, making it the type of harm that is especially hard to rectify," Leinenweber wrote.

In a news conference, Emanuel praised the ruling as an "affirmation of the rule of law."

A spokesman for the Department of Justice disagreed.

Copyright 2017 NPR. To see more, visit http://www.npr.org/.