By Dan Levine

SAN FRANCISCO (Reuters) - A U.S. 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 efforts to toughen immigration enforcement.

The ruling from U.S. District Judge William Orrick III in San Francisco said Trump's Jan. 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.

The Republican president's moves on immigration have galvanized legal advocacy groups, along with Democratic city and state governments, to oppose them in court. The administration suffered an earlier defeat when two federal judges suspended executive orders restricting travel from several Muslim-majority countries. The government has appealed those decisions.

In a statement, the U.S. Justice Department said it would follow existing federal law with respect to sanctuary jurisdictions, as well as enforce conditions tied to federal grants.

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. Dozens of local governments and cities, including New York, Los Angeles and Chicago, have joined the growing "sanctuary" movement.

Supporters of the sanctuary policy argue that enlisting police cooperation in rounding up immigrants for removal undermines communities' trust in local police, particularly among Latinos.

The Trump administration contends that local authorities endanger public safety when they decline to hand over for deportation illegal immigrants arrested for crimes.

The executive order by Trump, who made cracking down on illegal immigration a cornerstone of his 2016 presidential campaign, directed such funding to be restricted once the Homeland Security Department determines what constitutes a sanctuary city.

Story continues

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

'CRUMBLING UNDER THE WEIGHT'

The U.S. Justice Department threatened last week to cut some funding to California as well as eight cities and counties across the United States.

The department singled out Chicago and New York as two cities "crumbling under the weight of illegal immigration and violent crime," even though New York City is experiencing its lowest crime levels in decades and experts say Chicago's recent spike in violent crime has little to do with illegal immigration.

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 it said would affect only Justice Department and 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."

(Additional reporting by Julia Edwards Ainsley in Washington; Editing by Chris Reese and Peter Cooney)