Chicago Mayor Rahm Emanuel hailed a federal judge's decision on Sept. 15 barring the Justice Department from denying public-safety grants to sanctuary cities. (Reuters)

A federal judge on Friday blocked the Justice Department from withholding grant funds from places that do not provide immigration authorities access to local jails or give advance notice when suspected illegal immigrants are to be released — dealing a major blow to the Trump administration’s vowed crackdown on sanctuary cities.

U.S. District Judge Harry D. Leinenweber in Illinois wrote in a 41-page opinion that Attorney General Jeff Sessions had probably exceeded his lawful authority when he imposed new conditions on particular law enforcement grants, requiring recipients to give immigration authorities access to jails and notice when suspected illegal immigrants are to be released.

The judge blocked Sessions from implementing the conditions not just on the city of Chicago — which had sued over the matter — but also across the nation, writing that there was “no reason to think that the legal issues present in this case are restricted to Chicago or that the statutory authority given to the Attorney General would differ in another jurisdiction.”

His ruling follows an order from another federal judge in California blocking President Trump’s executive order on sanctuary cities.

Attorney General Jeff Sessions speaks in Washington on Sept. 11. (Zach Gibson/Getty Images)

In a statement, Justice Department spokesman Devin O’Malley said: “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. The Department of Justice will continue to fully enforce existing law and to defend lawful and reasonable grant conditions that seek to protect communities and law enforcement.”

Chicago Mayor Rahm Emanuel (D) said the ruling was an “affirmation of the rule of law” and “an assertion of our most fundamental American values.”

The judge issued a preliminary injunction, which means the administration is blocked temporarily while the case makes its way through the courts.

The Trump administration has waged an aggressive campaign against sanctuary cities — a term that generally refers to places that are welcoming to undocumented immigrants and resistant to federal authorities’ efforts to deport those in the country illegally.

Trump signed an executive order in January declaring that such places would not be eligible for federal grants, and Sessions has tried to make the threat a reality.

In April, the attorney general demanded that several jurisdictions produce proof that they are communicating with federal authorities about undocumented immigrants or risk losing grant funding.

In July, he announced new conditions on a particular pool of money — the Edward Byrne Memorial Justice Assistance Grant Program — requiring recipients to allow federal immigration authorities access to detention facilities and to provide 48 hours’ notice before releasing suspected illegal immigrants.

“So-called ‘sanctuary’ policies make all of us less safe because they intentionally undermine our laws and protect illegal aliens who have committed crimes,” Sessions said in announcing the change. “These policies also encourage illegal immigration and even human trafficking by perpetuating the lie that in certain cities, illegal aliens can live outside the law.”

The crackdown, though, has been stymied by the courts. A federal judge in San Francisco largely halted Trump’s executive order in April, though his ruling exempted the Edward Byrne Memorial Justice Assistance Grant Program, which already required places to certify they were complying with an immigration-related law.

After Sessions imposed the new conditions, Chicago, which received $2.33 million for itself and neighboring jurisdictions, sued, saying he was exceeding his authority. Chicago also said Sessions’s edict would put at risk funds for critical technology to detect when and where gunshots were fired.

Leinenweber largely agreed with the city, though he stopped short of saying it need not certify compliance with an immigration-related law tied to the grant. That law effectively says jurisdictions cannot block their employees from communicating with immigration authorities, though Leinenweber asserted it does not require local authorities to assist their federal counterparts.