CHICAGO — A U.S. district judge in Chicago on Friday denied a request by the U.S. Department of Justice to lift a national freeze on a Trump administration policy that seeks to withhold public safety grants to so-called sanctuary cities that don’t agree to tougher enforcement of U.S. immigration law.

Judge Harry Leinenweber’s ruling comes a month after he imposed the preliminary injunction blocking the administration from tying the grants to two new conditions, that cities notify immigration agents when someone in the country illegally is about to be released from jail and allow agents easy access to jails.

Attorney General Jeff Sessions argued it was wrong to apply an order nationally in a case brought by Chicago and that it should only apply to that city. Even before Friday’s ruling, the Justice Department already took its objections about the injunction and other legal issues to the Chicago-based U.S. 7th U.S. Circuit Court of Appeals.

Leinenweber agreed in his written ruling that such a sweeping freeze was an “extraordinary remedy” that a U.S. district judge shouldn’t resort to lightly. But he said the legal issues in the Chicago case impact cities and counties nationwide and so a nationwide injunction is called for.

“An injunction (that only applied to Chicago) would leave the Attorney General free to continue enforcing the likely invalid conditions against (those applying for the public safety grants),” he wrote. “This state of affairs flies in the face of the rule of law and the role of the courts to ensure the rule of law is enforced.”

Leinenweber said Chicago had demonstrated it will likely succeed in arguing that Sessions exceeded his authority with the new conditions, thereby justifying a freeze on the policy at least until the legal process fully plays out.

“The rule of law is undermined where a court holds that the Attorney General is likely engaging in legally unauthorized conduct, but nevertheless allows that conduct in other jurisdictions across the country,” Leinenweber wrote.

The Justice Department on Thursday said it was giving four cities — Chicago, New York, Philadelphia and New Orleans — a “last chance” to show they’re not thwarting enforcement of U.S. immigration law before possibly losing grants that help pay for police cars and public safety equipment.

It added that the four cities have until Oct. 27 to show they are complying with other, long-standing federal law, including a nearly 20-year-old statute that says cities can’t hinder information sharing with immigration agents.

It was unclear how that threat might be affected by the ongoing legal battle.

Chicago is leading the charge in court for cities and counties across the country. Dozens of jurisdictions have filed court briefs supporting Chicago’s lawsuit. At least seven cities and counties, including Seattle and San Francisco, as well as the state of California, are refusing to cooperate with the new federal rules.

Sessions has blasted sanctuary cities, often singling out Chicago.

Shortly after Chicago filed the lawsuit in August, Sessions said the Trump administration “will not simply give away grant dollars to city governments that proudly violate the rule of law and protect criminal aliens at the expense of public safety.” Chicago, he added, stood out in its “open hostility” to enforcing immigration laws.

Chicago Mayor Rahm Emanuel has said fully complying with the new Trump administration rules would “drive a wedge of distrust” between the immigrant community and the police force, which needs that community to trust police enough to come forward to report crimes and help officers solve them.