A US judge last night 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 US District Judge William Orrick III in San Francisco said Mr Trump's 25 January 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.
Reince Priebus, Mr Trump's White House chief of staff, told reporters the administration was taking action to appeal the ruling, adding: "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," Mr Priebus said, referring to the West Coast judicial district where the judge ruled. "We'll win at the Supreme Court level at some point."
A formal White House statement on the ruling was withering in its criticism of Judge Orrick, saying "an unelected judge unilaterally rewrote immigration policy for our nation" and handed "a gift to the criminal gang and cartel element in our country."
"This case is yet one more example of egregious overreach by a single, unelected district judge," the White House said.
The US Justice Department said in a statement 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 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 co-operation 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 Mr 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.
Santa Clara County, which includes the city of San Jose and several smaller Silicon Valley communities, sued in February, saying Mr Trump's order was unconstitutional. San Francisco filed a similar lawsuit.
The 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.7bn in federal and federally dependent funds annually, about 35% 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, Judge 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," the judge wrote.
The judge cited comments from Mr 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," Judge 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."
Trump's concession on wall funding removes obstacle from spending talks
The threat of a US government shutdown this weekend appeared to recede however after President Trump backed away from a demand that Congress include funding for his planned border wall with Mexico in a spending bill.
Even if the fight over wall funding is over, Republicans and Democrats still have difficult issues to resolve as they face a Friday night deadline when existing money expires for many federal agencies.
There was growing sentiment among lawmakers that they would need to pass a short-term extension of current spending, possibly of one week's duration, in order to finish negotiating longer-term legislation for funding the government to the end of September.
Mr Trump removed a crucial sticking point when he said on Monday he may wait until Republicans begin drafting the budget blueprint for the fiscal year that starts on 1 October to seek wall funding.
The president's fellow Republicans control both chambers of Congress, but the current spending bill will need 60 votes to clear the 100-member Senate, where Republicans hold only 52 seats.
Democratic leaders had said they would not support a bill that included funds for the wall.
The border wall was one of Trump's signature election pledges last year, with the Republican touting it as best way to stop illegal immigrants and drugs from coming into the country.
If no spending measure covering April 29 to Sept. 30 is in place before 12:01am (local time) on Saturday, government funds will halt and hundreds of thousands of the country's several million federal employees will be temporarily laid off.
Mr Trump had run the risk of being blamed by Democrats for a shutdown, which would start on his 100th day in office.
By dropping his call for immediate funding for the wall, Mr Trump may clear a path to a spending bill. But he will lose an opportunity to display serious progress on accomplishing his agenda since taking office in January.
There is also no guarantee that Congress will want to fund the wall later on, given skepticism running through the Republican Party.
Mr Trump said he had not changed his stance, tweeting yesteray about the issue.
Don't let the fake media tell you that I have changed my position on the WALL. It will get built and help stop drugs, human trafficking etc.
— Donald J. Trump (@realDonaldTrump) April 25, 2017
Mr Trump has said Mexico will eventually repay the US for wall construction, but the Mexican government has been adamant it will not do so, and Mr Trump has not laid out plans to compel repayment.
Internal Department of Homeland Security estimates have put the cost at $21.6bn.