A US judge on Tuesday blocked President Donald Trump's executive order that sought to withhold federal funds from so-called sanctuary cities, dealing another legal blow to the administration's immigration priorities.

The ruling from US District Judge William Orrick III of the Ninth Circuit in San Francisco said Trump's January 25 order targeted broad categories of federal funding for sanctuary governments and that plaintiffs challenging the order were likely to succeed in proving it unconstitutional.

“It’s the Ninth Circuit going bananas,” White House Chief of Staff Reince Priebus said from his West Wing office Tuesday evening, according to The Hill. “It’s clear forum shopping that’s going on in this country.”

Priebus reportedly sees appeals ultimately being decided at the US Supreme Court.

“We’re taking action to appeal this,” he said. “You’ll find out soon enough.”

The Trump administration suffered an earlier defeat in the courts when two federal judges suspended executive orders restricting travel from several Muslim-majority countries. The government has appealed those decisions.

Representatives for the US Justice Department and the White House were not immediately available for comment on the sanctuary ruling.

Sanctuary cities generally offer safe harbor to illegal immigrants and often do not use municipal funds or resources to advance the enforcement of federal immigration laws.

Santa Clara County, which includes the city of San Jose and several smaller Silicon Valley communities, sued in February, saying Trump's plan to withhold federal funds was unconstitutional. San Francisco filed a similar lawsuit.

Santa Clara County receives about $1.7 billion in federal and federally dependent funds annually, about 35 percent of its total revenues. The county argued it was owed millions of dollars of federal funding every day and that its budgetary planning process had been thrown into disarray by the order.

The Justice Department said the counties had taken an overly broad interpretation of the president's order, which would affect only Justice Department and Department of Homeland Security funds, a fraction of the grant money received by the counties.

In his ruling, Orrick said the language of the order made it clear it sought to withhold funds beyond law enforcement.

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

The judge cited comments from Trump calling the order “a weapon” to use against jurisdictions that disagree with his immigration policies.

“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 wrote.

Dave Cortese, president of the Santa Clara County Board of Supervisors, said in a statement: “The politics of fear emanating from the Trump White House has just suffered a major setback.”

There is no clear definition of "sanctuary city" in federal law, but Justice Department lawyer Chad Readler told the judge that the executive order would only apply to three programs administered by the DOJ or the Department of Homeland Security, "a very narrow range of funding," Readler told the judge, according to the San Francisco Chronicle.

Readler reportedly said that San Francisco doesn't currently receive funds from those programs, but that Santa Clara County receives about $1 million.

READ MORE: California one step closer to 'sanctuary state' despite threats from Trump admin

San Francisco and Santa Clara County argued their case based on the doctrine of anti-commandeering, a principle recognized by the US Supreme Court in the 1997 gun control case Printz v. United States. In that case, a conservative sheriff sued the government, and won, arguing he was not required to enforce federal gun background checks.