Acting on a lawsuit filed by the city of Chicago, a judge Friday said the Trump administration can’t withhold law-enforcement grant money from “sanctuary cities” that refuse to follow tough new Justice Department immigration requirements — such as giving federal agents access to municipal jails.

U.S. District Judge Harry Leinenweber sided with Chicago in its lawsuit against U.S. Attorney General Jeff Sessions, issuing a preliminary injunction with nationwide reach. The ruling means cities cannot be barred from receiving an annual federal grant based on their cooperation with immigration agents.

At City Hall on Friday, Mayor Rahm Emanuel said the court’s decision carried a message to the Trump administration that the “attempt to make a city abandon their values to seek resources, and abandon its principles of community policing, is wrong.”

“Chicago will never relinquish our status as a welcoming city,” he said. “It’s part of our history and our future.”

The city sued Sessions last month, after the U.S. Department of Justice ordered cities to: give notice 48 hours before releasing undocumented immigrants from custody; allow immigration agents access to jails; and share citizenship information with the feds.

Attorney General Jeff Sessions | Matt Rourke/AP

By not complying, the city would have been ineligible for Edward Byrne Memorial Justice Assistance Grants, the leading source of federal law enforcement grant funding.

The court held that the city was likely to prove Sessions exceeded his authority and that it would cause irreparable harm to provide notice of release, or to grant immigration agents access to jails.

Leinenweber did not issue an injunction blocking information sharing, however.

Chicago Corporation Counsel Edward Siskel said Friday the conditions require the city to choose between community policing and the values of a “welcoming city.” The mayor agreed, saying that following them would be “driving a wedge between our immigrant community and our police department.”

According to Bill McCaffrey, spokesman for the city’s law department, Chicago has applied for a $2.2 million grant the mayor said would be used for ShotSpotter gun-detection technology. McCaffrey said that $1.5 million from the grant will go directly to Chicago, while $450,000 will go to Cook County and the rest will be split among 10 suburbs.

As the city awaits a decision on that application, Emanuel said “this victory today is not just about to Chicago. … It is a win for cities, counties and states across the country.”

In his decision, Leinenweber said the injunction was nationwide because there is “no reason to think that the legal issues present in this case are restricted to Chicago.”

According to Siskel, 37 cities, counties and municipal organizations, and many other groups, filed briefs in support of the lawsuit.

One was filed by Mark Fleming, from the National Immigrant Justice Center. The center provides free legal services to immigrants, refugees and asylum seekers in Chicago, Indiana and Washington D.C.

Although Fleming thinks the court should revisit their decision on the condition of information sharing, he is happy the city won on “the two conditions that posed the greatest threats to immigrants and their ability to interact with the criminal justice system.”

Imposing the access and notification conditions “would have been a serious blow to the protection of immigrants in the city and also to the population at large,” Fleming said, “because we need everyone to feel safe and know that they can go to the police if they are involved with or witness to a crime.”

Justice Department spokesman Devin O’Malley said in an email Friday that the injunctions make the city of Chicago less safe and that sanctuary cities “undermine the rule of law” by protecting criminals from immigration enforcement.

Contributing: Jon Seidel