A federal judge in San Francisco has blocked President Donald Trump's executive order withholding federal funds from cities which refuse to cooperate with federal immigration authorities, handing San Francisco and Santa Clara County court injunctions on the Jan. 25 order.

The ruling is a blow to Trump's tough talk on undocumented immigration, as well as his stated intention to deport millions in the face of localities like San Francisco, Chicago and New York which have refused to direct their police departments to help out.

U.S. District Judge William Orrick wrote that the order, in which Trump ordered the withholding of all federal grants from non-cooperative cities, was not "legally plausible" and that "the Constitution vests the spending powers in Congress, not the president, so the order cannot constitutionally place new conditions on federal funds."

Orrick noted that even the administration's own lawyers had agreed the wording of the order was overly broad, and argued it violated the separation of powers in the Constitution as well as the Fifth and 10th Amendments.

The ruling could be appealed by the administration in the U.S. Court of Appeals in San Francisco.

While Trump had promised to prevent so-called "sanctuary cities" from receiving any federal funding or "taxpayer dollars" at all, a Time analysis found the administration had only threatened to withhold a few million dollars in Department of Justice or Department of Homeland Security funding, small by government standards.

On Tuesday, U.S. Attorney General Jeff Sessions appeared to adopt a very narrow definition of the term "sanctuary city," which would place very few or no local governments at risk of losing federal grants. Even before that, Trump's own legal teams appeared to acknowledge the president's power to withhold any funds was limited at best.

San Francisco's victory is the second major loss in court for Trump's administration; in March, his second attempt at an executive order banning refugees and travelers from seven Muslim-majority countries from entering the U.S. was blocked by judges in Hawaii and Maryland.