CHICAGO (Reuters) - A federal judge on Friday barred the U.S. Justice Department from denying public-safety grants to so-called sanctuary cities in retaliation for limiting cooperation with the Trump administration’s crackdown on illegal immigration.

The preliminary injunction issued by U.S. District Judge Harry Leinenweber was in response to a legal challenge brought by Chicago, the third-largest city in the United States, but the judge ruled that his order would be applied on a nationwide basis.

Chicago sued in August after U.S. Attorney General Jeff Sessions announced he would cut off cities from certain Justice Department grants unless they allowed federal immigration authorities unlimited access to local jails and provided 48 hours’ notice before releasing anyone wanted for immigration violations.

The lawsuit contended that Sessions exceeded his authority by imposing new conditions beyond those Congress prescribed when it established the grant program. In his injunction, Leinenweber found the city likely to prevail on the merits of its argument once the case is considered in its entirety.

Chicago Mayor Rahm Emanuel hailed Friday’s decision at a City Hall news conference as “an affirmation of the rule of law.”

“It’s an assertion of our most fundamental American values and it’s an unambiguous, clear rejection of the false choice that the Trump Justice Department wanted Chicago to make between our values, our principles and our priorities,” Emanuel said.

A Justice Department spokesman, Devin O’Malley, declined comment when asked whether the administration would appeal the court order.

U.S. President Donald Trump delivers remarks to military personnel and families at Joint Base Andrews Maryland, U.S., September 15, 2017. REUTERS/Yuri Gripas

President Donald Trump has made tougher immigration enforcement a centerpiece of his campaign and presidency, along with a pledge to build a wall on the U.S.-Mexican border.

As part of that policy, the Justice Department has sought to punish cities and other local jurisdictions that have joined a growing “sanctuary” movement aimed at shielding illegal immigrants from stepped-up deportation efforts.

The Trump administration has argued that its deportation crackdown is focused on illegal immigrants convicted of serious crimes, and that public safety is jeopardized when police refuse to notify U.S. Immigration and Customs Enforcement of plans to release such a person from local custody.

“By protecting criminals from immigration enforcement, cities and states with ‘so-called’ sanctuary policies make their communities less safe and undermine the rule of law,” O’Malley said.

But critics counter that enlisting police cooperation in rounding up immigrants for removal undermines communities’ trust in local law enforcement, particularly among Latinos, and they have questioned whether the administration is really targeting dangerous criminals.

Trump’s opponents also say there is no correlation between immigration and violent crime, citing a sharp drop in homicides in Los Angeles since the early 1990s, despite embracing the sanctuary cities movement.

The grants at issue, under the Edward Byrne Memorial Justice Assistance Grant, or Byrne JAG, program typically are used to help police improve crime-fighting techniques, buy new equipment and assist victims of crime.

Federal records show the Justice Department doled out $1 billion in Byrne JAG money to state governments, $430 million to nonprofits and $136 million directly to cities and counties last year. Chicago is expected to receive $3.2 million this year for purchasing equipment.

Dozens of cities have taken a stance on deportation enforcement similar to Chicago’s including New York, Los Angeles, Philadelphia and New Orleans.

Police agencies in those jurisdictions have generally barred their officers from routinely checking individuals’ immigration status when making arrests or traffic stops. And they have refused to keep anyone locked up longer than otherwise warranted at the request of federal agents seeking to deport them.