The Trump administration tried to stop federal funding to local authorities in cities such as New York, Los Angeles and Chicago, that decline to hand over undocumented immigrants to the federal government.
A US district judge on Tuesday blocked President Donald Trump's executive order that sought to withhold federal funds from "sanctuary cities" that protect undocumented immigrants.
The ruling, another legal blow to Trump's efforts to toughen immigration enforcement, said the order targeted broad categories of federal funding for sanctuary governments.
US District Judge William Orrick III in San Francisco said plaintiffs challenging Trump's January 25 immigration order against Muslim-majority countries were likely to succeed in proving it unconstitutional.
The Republican president's moves against immigration have galvanised legal advocacy groups, along with city and state governments where Democrat majorities hold office, to oppose them in court.
TRT World's Lorna Shaddick has more on the ruling from New York.
Second legal blow
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.
Reince Priebus, Trump's White House chief of staff, told reporters the administration was taking action to appeal the ruling.
"The idea that an agency can't put in some reasonable restrictions on how some of these monies are spent is something that will be overturned eventually."
"It's the 9th Circuit going bananas," Priebus said, referring to the West Coast judicial district where the judge ruled. "We'll win at the Supreme Court level at some point."
Sanctuary cities generally offer safe harbour 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 directed such funding to be restricted once the Homeland Security Department determines what constitutes a sanctuary city.
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.