Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

Philadelphia scored a legal victory in its fight to keep federal funding Wednesday after a judge issued a preliminary injunction barring the Justice Department from withholding more than $1 million in crime-fighting aid over the city's so-called sanctuary city policies.

The department has argued that Philadelphia — along with several other major cities and counties — does not appear to be in compliance with federal immigration law, does not meet the other conditions of the grant and therefore should not receive funds.

But U.S. District Judge Michael Baylson ruled Wednesday that the city was "in substantial compliance" with the statute governing the grant and said denying Philadelphia $1.6 million in aid would cause "irreparable harm."

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

"The city’s policies do not protect illegal aliens who commit crimes," Baylson said. "Criminal aliens are not shielded from criminal prosecution or from federal immigration authorities."

"Given Philadelphia’s unique approach to meshing the legitimate needs of the federal government to remove criminal aliens with the city’s promotion of health and safety, there is no conflict of any significance," he added.

The DOJ grant, which supports law enforcement and prosecution, among other crime-fighting areas, covers about 10 percent of the Philadelphia Police Department's budget, according to the court documents.

Baylson also ruled that two new strings attached to the grant's disbursement — giving U.S. Immigration and Customs Enforcement access to local jails as well as a requirement that city officials tell ICE about suspected undocumented immigrants in police custody within 48 hours — did not have a relationship to the grant program.

“I am gratified that the judge recognized what the city has maintained all along," City Solicitor Sozi Pedro Tulante said Wednesday. "We are in compliance with federal law, and attaching immigration-related conditions to a grant having nothing to do with immigration is harmful to Philadelphians’ safety."

The Justice Department criticized Wednesday's ruling, the latest setback in the Trump administration's efforts to crack down on sanctuary cities.

“In Philadelphia, 2017 homicides have already eclipsed 2016’s numbers, and so-called ‘sanctuary policies’ further undermine public safety and law enforcement. The Justice Department is reviewing the ruling and determining next steps," Devin M. O’Malley, a DOJ spokesman, told NBC News.

Philadelphia Mayor Jim Kenney speaks at City Hall in Philadelphia on Nov. 2, 2017. Matt Rourke / AP

Federal courts in Chicago and San Francisco have also blocked the Trump administration from halting the grants earlier this year, which the department is appealing.

Hours after Wednesday's ruling, the Justice Department announced it was expanding its effort to halt funds to sanctuary cities. The department put 29 local governments on notice of losing a total of $21 million in law enforcement grants.