SAN FRANCISCO ― A federal judge blocked President Donald Trump’s executive order targeting so-called “sanctuary” jurisdictions on Tuesday, just as the White House was looking for victories to celebrate from the president’s first 100 days in office.

Trump’s order was challenged by the city and county of San Francisco and the county of Santa Clara, California, two of the jurisdictions under presidential fire for limiting their cooperation with U.S. Immigration and Customs Enforcement.

Tuesday’s legal setback is yet another defeat for Trump, whose executive orders, particularly those related to immigration, have met resistance in the courts. U.S. District Judge William Orrick issued a nationwide preliminary injunction blocking the order’s enforcement, effectively preventing the administration from pulling federal funds from the sanctuary jurisdictions that sued and others that may likewise feel their federal funding is at risk if they don’t go along with Trump’s anti-immigrant policies.

“The Constitution vests the spending powers in Congress, not the President, so the Order cannot constitutionally place new conditions on federal funds,” wrote Orrick, who was nominated to the court by then-President Barack Obama. “Federal funding that bears no meaningful relationship to immigration enforcement cannot be threatened merely because a jurisdiction chooses an immigration enforcement strategy of which the President disapproves,” Orrick added.

The judge held that the executive order, which Trump signed during his first week on the job, is likely unconstitutional because it is too vague and would likely deprive the localities of monies that are rightly theirs, which would violate the Fifth Amendment. The judge also said the order likely violates the 10th Amendment and the separation of powers.

Trump reacted to the news early Wednesday by bashing a court.

First the Ninth Circuit rules against the ban & now it hits again on sanctuary cities-both ridiculous rulings. See you in the Supreme Court! — Donald J. Trump (@realDonaldTrump) April 26, 2017

Out of our very big country, with many choices, does everyone notice that both the "ban" case and now the "sanctuary" case is brought in ... — Donald J. Trump (@realDonaldTrump) April 26, 2017

...the Ninth Circuit, which has a terrible record of being overturned (close to 80%). They used to call this "judge shopping!" Messy system. — Donald J. Trump (@realDonaldTrump) April 26, 2017

But it wasn’t the U.S. Court of Appeals for the 9th Circuit that ruled on the case. So far, the matter is still in the district court ― although an appeal of the judge’s ruling would go to the 9th Circuit. Moreover, this isn’t an example of “judge shopping” or “circuit shopping.” The plaintiffs in the case simply sued in their local federal court, where cases are assigned randomly to any of the several judges serving there.

Orrick issued the ruling less than two weeks after he heard arguments in the case. At the April 14 hearing, a Justice Department lawyer urged a more narrow interpretation of the president’s order, arguing that only a select few grants were at risk under the order and contending that very little funding for San Francisco and Santa Clara County programs would be affected.

The judge appeared skeptical of that argument at the hearing and explicitly took issue with it in his ruling, calling it “not legally plausible.” He cited comments by both Trump and Attorney General Jeff Sessions that directly contradicted the Justice Department’s argument in court. (Sessions last month vowed to “claw back” funds from sanctuary cities, while Trump has described using defunding as a “weapon” against cities that refuse to cooperate with policies targeting undocumented immigrants.)

“If there was doubt about the scope of the Order, the President and Attorney General have erased it with their public comments,” Orrick wrote.

He also said that the Justice Department’s narrow reading of the order was in direct conflict with its actual text.

“The Government attempts to read out all of Section 9(a)’s unconstitutional directives to render it an ominous, misleading, and ultimately toothless threat,” Orrick wrote. “This interpretation is in conflict with the Order’s express language and is plainly not what the Order says. ... A construction so narrow that it renders a legal action legally meaningless cannot possibly be reasonable and is clearly inconsistent with the Order’s broad intent.”

The Justice Department also argued at the April 14 hearing that the order constituted a “perfectly permissible use of the bully pulpit” and served the purpose of promoting immigration enforcement as a presidential priority.

But in his ruling, Orrick wrote that because executive orders carry the force of law, it’s not reasonable to interpret them simply as rhetorical devices.

“The President certainly has the right to use the bully pulpit to encourage his policies,” the judge wrote. “But Section 9(a) is not simply rhetorical.”

In several parts of his ruling, Orrick relied on none other than Chief Justice John Roberts’ opinion in the 2012 Affordable Care Act case, which took aim at Congress and the Obama administration for placing a “gun to the head” of states that rely on Medicaid funding for survival.

“The threat is unconstitutionally coercive,” Orrick said of Trump’s order, which he likened to Obamacare’s Medicaid expansion.

San Francisco and Santa Clara County, meanwhile, had demonstrated that they were “likely to face immediate irreparable harm” if the order weren’t blocked, Orrick said, and that they are likely to succeed in challenging the order as unconstitutional if the litigation proceeds.

“The Order’s uncertainty interferes with the Counties’ ability to budget, plan for the future, and properly serve their residents,” he wrote. “Without clarification regarding the Order’s scope or legality, the Counties will be obligated to take steps to mitigate the risk of losing millions of dollars in federal funding, which will include placing funds in reserve and making cuts to services. These mitigating steps will cause the Counties irreparable harm.”

The Trump administration has yet to clarify what exactly it considers to be a “sanctuary city,” creating considerable confusion for local officials trying to determine whether their funding could be at risk. A spokesman for the Department of Homeland Security said Tuesday that it still hasn’t finalized a definition and will not cut any grants until it does.

Orrick left open the possibility that Sessions or DHS Secretary John Kelly could issue further guidelines as to how exactly the federal government defines a “sanctuary” jurisdiction. He also didn’t bar the Trump administration from seeking compliance with a provision of federal law that directs cities to report the status of certain undocumented immigrants.

The term “sanctuary city” is used to cover a wide array of policies, but is most often applied to jurisdictions that do not honor all ICE “detainers” ― that is, requests from the federal government that local law enforcement hold individuals with problematic legal status whom police would otherwise release. The jurisdictions that decline detainers have a variety of reasons: They say it’s bad for public safety for people to equate the police with ICE, expensive to hold individuals for extra time on the federal government’s behalf, and even unconstitutional to do so.

The Trump administration has tried to legally justify its threats by citing a part of the U.S. code that requires jurisdictions to share information with federal law enforcement ― which nearly all of them do to some degree. Mayors and law enforcement leaders who met with Sessions on Tuesday said the impression they got from him was that the federal government will define the term “sanctuary city” more narrowly to cover jurisdictions that don’t share such information.

“Based on what we’ve heard, I don’t know of any cities that are out of compliance with that at the moment,” New Orleans Mayor Mitch Landrieu said, according to Politico.

After the ruling, a Justice Department spokesman said that because the judge’s order does not impact that portion of the U.S. code requiring cities to share information, the Trump administration will continue to “follow the law with respect to regulation of sanctuary jurisdictions.”

“Accordingly, the Department will continue to enforce existing grant conditions and will continue to enforce 8 U.S.C. 1373,” said spokesman Ian Prior. “Further, the order does not purport to enjoin the Department’s independent legal authority to enforce the requirements of federal law applicable to communities that violate federal immigration law or federal grant conditions.”

Santa Clara County Supervisor Cindy Chavez told HuffPost that the judge’s ruling shows that policies like her county’s aren’t breaking the law ― they’re protecting it. “We were following the law,” Chavez said. “The president was trying to get us to violate the Constitution and violate people’s constitutional rights, and we said no to that. So what I think it tells everybody across the country, every jurisdiction, is when you’re fighting for the Constitution and you’re preserving the rights of people who live, work, play in your jurisdiction, we’ve got to do this collectively, we’ve got to do it boldly, and we’ve got to do it with one voice.” San Francisco City Attorney Dennis Herrera also praised the ruling in a press conference Tuesday afternoon. He noted that Trump’s public comments on the issue ultimately hurt his administration’s legal case, and he suggested the administration move on rather than attempt to re-write the executive order. “Words matter and what the president said in public as a candidate and after he was sworn in certainly impacted how the court viewed this case,” Herrera said. “That inconsistency hurt the presentation of the government’s case, so I think it’s best that they move on from that and just focus on the law.”

Read Orrick’s ruling below:

Federal Judge Strikes Down Sanctuary Cities Order on Scribd

This story has been updated throughout. Mollie Reilly reported from San Francisco; Elise Foley reported from Washington; Cristian Farias reported from New York.