SAN FRANCISCO (CBS SF) — A federal judge in San Francisco Tuesday issued a nationwide preliminary injunction blocking an executive order by President Donald Trump that threatened to deny federal funding to sanctuary cities and counties.

U.S. District Judge William Orrick ruled in a pair of lawsuits filed by the city of San Francisco and Santa Clara County.

READ MORE: 'Fire Hose' Of Subtropical Moisture Bearing Down On Northern California

He said the order violates the constitutional separation of powers doctrine because it intrudes on Congress’s spending powers.

ALSO READ: Justice Dept. Intensifies Effort To Crack Down On Sanctuary Cities

The directive issued by Trump on Jan. 25 would deny federal funding to cities, counties and states deemed by the Trump administration to be sanctuary jurisdictions shielding undocumented immigrants from federal deportations.

Orrick wrote that the “plain language” of the order refers to all federal funding and said it is unconstitutional for the executive branch to place new, retroactive conditions on federal funds.

“The Constitution vests the spending powers in Congress, not the president, so the order cannot constitutionally place new conditions on federal funds,” Orrick wrote.

“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,” the judge said in the ruling.

ALSO READ: Oakland City Council Approves Measure Encouraging Sanctuary Workplaces

Orrick rejected an argument made at a hearing earlier this month by a U.S. Department of Justice lawyer who contended the order should be interpreted narrowly to apply only to a limited set of federal criminal justice grants.

The judge said that argument was not plausible because the wording of Trump’s order addressed all federal funding and because Trump and Attorney General Jeff Sessions had made broad statements threatening to withhold, terminate or claw back federal funding.

“If there was doubt about the scope of the order, the president and attorney general have erased it with their public comments. The president has called it ‘a weapon’ to use against jurisdictions that disagree with his preferred policies of immigration enforcement.” Orrick wrote.

ALSO READ: Santa Rosa Immigrant, Mother Of 3 Detained By ICE Seeks Bond Hearing

The judge also said the order was unconstitutionally vague because it did not define the phrases “sanctuary jurisdiction” and “willfully refuse to comply” with federal law.

READ MORE: Kid-Size Doses Of Pfizer’s COVID-19 Vaccine More Than 90% Effective

He said his ruling did not prevent the government from enforcing any existing conditions imposed on federal grants or from developing regulations to define a sanctuary jurisdiction.

The San Francisco and Santa Clara County lawsuits were among several filed around the nation to challenge the executive order, but were the first to receive a judicial ruling. Another of the pending lawsuits was filed in federal court in San Francisco by the city of Richmond.

Santa Clara County said it had $1.7 billion in annual federal funding at stake and San Francisco had $1.2 billion.

Santa Clara County Supervisors Dave Cortese said at a news conference in San Jose, “The politics of fear suffered a major setback today thanks to Judge Orrick.

“Because of Judge Orrick’s ruling, millions of people across the country can continue to receive essential medical care, continue to go to school, continue to be active members of their community without fear that their local governments will be forced to work against them, rather than for them,” Cortese said.

Supervisor Joe Simitian said, “This is also a victory for taxpayers. Santa Clara County taxpayers send their dollars to Washington with the reasonable expectation that those dollars will come back from the federal government to do good work here”

San Francisco City Attorney Dennis Herrera called the decision “a fairly strong rebuke” to Trump.

The ruling is “substantial on virtually every issue that the court found in our favor,” he said at a City Hall news conference.

The U.S. Justice Department did not immediately respond to a request for comment.

California Attorney General Xavier Becerra, who filed a friend-of-the-court brief supporting the lawsuits, said, “As California continues to abide by the Constitution, yet another court has ruled against the Trump administration’s executive overreach.”

Trump suffered a similar setback when several federal courts struck down parts or all of two versions of an executive order restricting travel from several predominantly Muslim countries.

The Trump administration’s appeal of a ruling by a federal judge in Hawaii overturning the most recent order is due to be argued before the 9th U.S. Circuit Court of Appeals at a hearing in Seattle in May.

MORE NEWS: Support Builds for KPIX Reporter Targeted in YouTuber's Racist Remarks

© Copyright 2017 by CBS San Francisco and Bay City News Service. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.