A federal judge has blocked the federal government's attempt to withhold law-enforcement money from Philadelphia over its so-called "sanctuary city" status.

U.S. District Judge Michael Baylson issued a massive 128-page ruling Wednesday, writing that after applying the appropriate legal standards, which include probability of success on the merits and the public interest, "the court will issue a preliminary injunction in favor of the city."

"This is a very, very significant day for the city of Philadelphia," said city solicitor Sozi Pedro Tulante at an afternoon news conference. Still, Mayor Kenney said: "This is not a time for jubilation. I'm very grateful to the court, but I'm angry we have to fight our own federal government when we have problems we could be addressing together that [the Trump administration] refuses to address because it doesn't play to their base."

The ruling comes two weeks after Baylson declared from the bench that the city of Philadelphia substantially complied with the Trump administration's conditions.

At the heart of the case is a relatively small amount of money — a $1.5 million federal grant to a city with a $4.4 billion budget — but a big principle: whether the Trump administration can withhold money unless the city agrees to more actively help federal agents identify and arrest people who immigrated without appropriate documents. The funds make up about 10 percent of the department's non-personnel budget, officials said.

City officials touted the ruling as a victory — and said that Philadelphia could be a model for other cities fighting the Trump administration on its immigration policies. Hours after the ruling was issued, the Department of Justice warned another 29 cities and counties that their "sanctuary" policies could be in violation of federal law — as it had warned Philadelphia earlier this year.

But Baylson, a Reagan appointee, ruled that the city did comply with a federal law banning municipalities from restricting contact with ICE, the first ruling of its kind since cities began challenging the Justice Department's attempts to pull funding. That law, Tulante said, "is arguably the whole ballgame. And today Philadelphia won on that issue."

Justice Department spokesman Devin O'Malley said Wednesday that officials were "reviewing the ruling and determining next steps."

He highlighted the city's homicide rate and said that "so-called 'sanctuary policies' further undermine public safety and law enforcement."

Police Commissioner Richard Ross testified last month that most people who commit crimes in the city are natural-born Philadelphians, not immigrants. And Baylson wrote in his opinion that the government had not proved there was a link between the city's policies and increases in crime.

"I don't know what [the homicide rate] has to do with immigrants," Kenney said Wednesday. "It has to do with the fact that the Second Amendment has run wild — if they want to blame someone for homicide in our society, they should look in the mirror, because they won't do anything about guns."

The city filed suit against Attorney General Jeff Sessions in August.

"Both the federal government and the city of Philadelphia have important interests at stake here and the court does not minimize either of their concerns," the judge wrote. "In this case, 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."

Broadly defined, a sanctuary city limits its cooperation with federal authorities who enforce immigration law. Those cities' leaders aim to ease fears of deportation among undocumented residents, believing that members of immigrant communities will then be more willing to report crime.

"We are really, really supportive of the efforts of the mayor's office to defend our sanctuary city policies," said Cynthia Oka, an organizer with the New Sanctuary Movement, which works to end injustices against immigrants. "We also really look forward, now that they've won, to continue working with the city to expand the sanctuary city policies. For us 'sanctuary city' means protection and fair access for all residents of Philadelphia, for all of the city services as well as to due process of law."

President Trump and Sessions have argued that sanctuary city policies allow dangerous criminals to be released to prey on local neighborhoods when instead they should be returned to their homelands. The administration aims to withhold grant money as a means to make cities assist federal agents seeking to deport undocumented immigrants.

Philadelphia officials say they reject the title of "sanctuary city," that they simply enforce city policies that provide equal treatment for people who come in contact with the criminal-justice system, regardless of immigration status. Immigrants who commit crimes are arrested and charged, just like anyone else, city officials said.

In his decision, the judge summoned tales from Greek mythology, German folklore, and the New Testament to show there was nothing inherently wrong with imposing conditions on the receipt of benefits, in this case a federal grant.

"The operatic hero Orfeo was allowed to escape Hades with his deceased and beloved Eurydice, conditioned on his not looking at her, but when he does, she dies; Mephistopheles grants Faust eternal knowledge and pleasure on the condition that Faust surrender his soul; and Salome, the title character demands the head of St. John the Baptist as a condition to dance for King Herod," the judge wrote. "However, in real life, the courts, in interpreting the Constitution, and Congress in enacting laws, as detailed at some length in this memorandum, have interposed restrictions on the Executive's ability to impose conditions on the transfer of benefits to local governments."

Barring appeals, the ruling would clear the way for the city to receive the federal money for police overtime, training, and other improvements.

Anil Kalhan, a Drexel University immigration law professor, said the city's arguments in the case are strong. But, he said, the federal government will almost certainly appeal the decision.

"It's a preliminary win — these kinds of conflicts are going to keep re-emerging for a while," he said. "This tees up the question: 'What are the limits of what the executive branch can do on its own?' "

City officials testified during two days of hearings last month that they willingly turn over information about undocumented people who have been convicted or who are actively under suspicion of committing a serious crime.

"Isn't that all you're entitled to?" the judge asked Chad Readler, the Trump administration's acting assistant attorney general for the civil division.

If federal agents were willing to accept that without demanding information on every person about whom they inquire, Baylson told Readler,"we wouldn't be here."