In his ruling, Judge William H. Orrick sided with Santa Clara County, the city of San Francisco and other jurisdictions, who argued that a threat to take away federal funds from cities that do not cooperate with some federal immigration enforcement could be unconstitutional.
In making the ruling apply nationwide, Orrick blocked the government from enforcing a key portion of Trump's January executive order on immigration, which ordered the Department of Homeland Security and Justice Department to block cities who do not cooperate with federal immigration enforcement from receiving federal funds.
Attorney General Jeff Sessions on Wednesday evening pledged the Justice Department would continue to litigate the case. In a statement, he said these executive actions were "squarely within the powers of the President."
"This is the Trump era," Sessions said in a statement. "Progress is being made daily, and it will continue. This will be the Administration that fully enforces our nation's immigration laws."
The statement did not outline the Justice Department's next steps.
While Orrick's ruling does not find the policy unconstitutional, he did find that the counties and cities that challenged the law demonstrated they could face "immediate irreparable harm" if the policy were allowed to be put into place, and that their constitutional challenge could succeed once the case is fully heard.
In a scathing late-night statement, the White House on Tuesday called the ruling an "egregious overreach by a single, unelected district judge."
"Today's ruling undermines faith in our legal system and raises serious questions about circuit shopping. But we are confident we will ultimately prevail in the Supreme Court, just as we will prevail in our lawful efforts to impose immigration restrictions necessary to keep terrorists out of the United States," the statement says.
Trump, himself, expressed frustration about the ruling Wednesday morning, tweeting: "First the Ninth Circuit rules against the ban & now it hits again on sanctuary cities-both ridiculous rulings. See you in the Supreme Court!"
White House chief of staff Reince Priebus vowed Tuesday to "take action" to appeal the ruling.
"It's the 9th Circuit going bananas," Priebus told CNN and other reporters during an interview in his West Wing office, referring to the appellate court that would hear an appeal to the case and has already sparred with the administration.
He called it "forum shopping" -- and said it was absurd that an administration could not put in a "reasonable restriction on how this money is spent."
In a statement, the Justice Department said it would continue to enforce grant requirements and compliance with the law. The Department of Homeland Security declined to comment.
The judge did leave the government some wiggle room, saying that his order does not block the government from enforcing conditions on federal grants nor does it block the government from creating a definition of sanctuary jurisdictions -- but the government will not be able to block federal funds from going to those cities as Trump ordered.
Orrick wrote that the jurisdictions successfully showed they "are currently suffering irreparable harm" because the order violates rights granted to states by the Constitution and because, even if the order hasn't been carried out, it has "caused budget uncertainty" simply by threatening to take away hundreds of millions in federal funds.
"The Counties have demonstrated that they are likely to succeed on the merits of their challenge to Section 9(a) of the Executive Order, that they will suffer irreparable harm absent an injunction, and that the balance of harms and public interest weigh in their favor," Orrick wrote.
"This is an absolutely huge win," James Williams, counsel to Santa Clara County, told CNN. "The threat to withhold funds from state and local governments in this executive order is dead."
"Faced with the law, the Trump administration was force to back down," San Francisco city attorney Dennis Herrera said in a statement. "This is why we have courts -- to halt the overreach of a president and an attorney general who either don't understand the Constitution or choose to ignore it."
If the case is appealed, it will go before the 9th Circuit Court, a body whose judges trend to the left. It was the 9th Circuit that upheld a nationwide block on Trump's controversial first travel ban, a ruling that effectively forced the administration to re-write the law in a second attempt to get it past the courts. That second attempt has also been blocked as it works its way through the process. Williams said lawyers are "absolutely" prepared to defend the ruling and are "very confident" they will prevail.
The question of what constitutes a "sanctuary jurisdiction" under the executive order, and which funds would be taken away, has been a central question for cities since it was issued. The Trump administration has made threats to punish sanctuary jurisdictions a key piece of Trump's immigration agenda.
The whole debate seemingly hinges on an obscure piece of US law. Since there is little federal law requiring jurisdictions to cooperate with federal law enforcement, the executive order only mentioned one small piece of US law, which requires jurisdictions to tell the federal government about a person's citizenship status.
While the order seemed to threaten to jeopardize all federal funds for cities the administration deemed non-cooperative, it didn't make clear what the threshold would be beyond that small law. Since the order was issued three months ago, the government has said that a definition of sanctuary jurisdictions would be forthcoming.
That uncertainty was a central focus of the arguments in the case, as well. At a hearing earlier this month, attorneys for the Justice Department offered a far narrower interpretation of the order than Trump, saying it would only apply to jurisdictions that refuse to share citizenship information as required by law, and that it would apply to only three federal grants from the Departments of Justice and Homeland Security that require compliance as a pre-condition.
Orrick was skeptical of that interpretation.
"This interpretation renders the order toothless," Orrick wrote. "The government can already enforce these three grants by the terms of those grants and can enforce 8 U.S.C. 1373 to the extent legally possible under the terms of existing law."
San Francisco also challenged that law itself, but the judge postponed hearing those arguments until next month.
Trump's rhetoric comes back to bite
As with Trump's travel ban, the judge looked at Trump's own rhetoric and statements of his surrogates -- saying those contradicted the "new, narrow interpretation" that government lawyers presented in court.
The judge used specific statements by the President and his administration against the government's lawyers, saying they left no doubt about the intent of the executive order.
"If there was doubt about the scope of the order, the President and Attorney General have erased it with their public comments," Orrick said. "The President has called it 'a weapon' to use against jurisdictions that disagree with his preferred policies of immigration enforcement, and his press secretary has reiterated that the President intends to ensure that 'counties and other institutions that remain sanctuary cites don't get federal government funding in compliance with the executive order.'"
The administration faced concern from local jurisdictions about the threats. Law enforcement chiefs and mayors alike questioned the administration's threat to remove even law enforcement funding from cities as part of a stated goal to improve public safety. Local officials argued their so-called sanctuary policies were in fact designed to protect public safety, by making undocumented immigrants feel safe to work with law enforcement as witnesses to crimes.
Asked about the threat to take away law enforcement monies, White House press secretary Sean Spicer said in a briefing last month that the administration stood behind its threat.
"You can't be a sanctuary city and at the same time seem to pretend or express concern about law enforcement or ask for more money when probably a number of the funds that you're using in the first place are going to law enforcement to handle the situation that you've created for yourself," Spicer said.
Persistent confusion over order
The complaints about confusion over the order persisted for the three months it was in effect.
Also on Tuesday, a group of mayors and major police chiefs met with Sessions at the Justice Department in Washington to talk about the very issue.
New Orleans Mayor Mitch Landrieu called the meeting "productive" in a briefing with reporters afterward, but said mayors still lacked "focus and clarity" from the administration on which cities were at risk of losing money and how much.
Other mayors came away from the meeting with the impression that the order would actually be enforced in a very narrow way, saying the interpretation that Orrick later in the day called "toothless" was what they were told would go into effect.
Providence, Rhode Island Mayor Jorge Elorza said he understood the definition of 'sanctuary jurisdiction' to be limited to the law on transmitting citizenship information -- which most cities comply with already.
"If that's the definition of 'sanctuary city' is then I don't think there are any 'sanctuary cities' in the United States of America," Elorza said, adding that from what he's been told from lawyers the amount of funds the US could take away under the policy "is close to zero."
Similarly, Austin, Texas Mayor Steve Adler, whose city is often attacked by conservatives as a prime example of sanctuary jurisdictions, said he walked away thinking his federal funds would be safe.
"Based on the conversation we've had last night and today, I don't think Austin and Travis County qualify as a sanctuary city," Adler said.
Department of Homeland Security spokesman David Lapan told reporters in a separate briefing Tuesday held before the ruling, the agency had not yet settled on a definition of sanctuary jurisdictions. He said it might not include some of the things DHS would like cities to do, like honor requests to hold people in jail extra time so that immigration agents can pick them up. Many cities have said they are bound by judges' rulings to not honor those requests.
But Lapan said just starting conversations with cities had accomplished part of the goals of the administration already.
"It's not on hold (while we come up with a definition), we are having ongoing discussions with communities about what they can do to, again, honor detainers, to provide notice, to do all the things that we're asking them to do," Lapan said. "And so, having those discussions with jurisdictions is one way to come to an agreement."