SAN FRANCISCO (AP) - A federal judge on Tuesday blocked President Donald Trump's attempt to withhold funding from "sanctuary cities" that do not cooperate with U.S. immigration officials, saying the president has no authority to attach new conditions to federal spending.
U.S. District Judge William Orrick issued the preliminary injunction in two lawsuits - one brought by the city of San Francisco, the other by Santa Clara County - against an executive order targeting communities that protect immigrants from deportation.
The injunction will stay in place while the lawsuits work their way through court.
The judge rejected the administration's argument that the executive order applies only to a relatively small pot of money and said Trump cannot set new conditions on spending approved by Congress.
Even if the president could do so, those conditions would have to be clearly related to the funds at issue and not coercive, as the executive order appeared to be, Orrick said.
"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.
It was the third major setback for the administration on immigration policy.
White House chief of staff Reince Priebus described the ruling as another example of the "9th Circuit going bananas."
The administration has often criticized the 9th U.S. Circuit Court of Appeals. Orrick does not sit on that court but his district is in the territory of the appeals court, which has ruled against one version of Trump's travel ban.
"The idea that an agency can't put in some reasonable restriction on how some of these moneys are spent is something that will be overturned eventually, and we will win at the Supreme Court level at some point," Priebus said.
San Francisco City Attorney Dennis Herrera praised the ruling and said the president was "forced to back down."
"This is why we have courts - to halt the overreach of a president and an attorney general who either don't understand the Constitution or chose to ignore it," Herrera said in a statement.
Santa Clara County Counsel James Williams said the ruling will allow cities and counties across the country to prepare budgets without the "unconstitutional threat of federal defunding hanging over our heads."
A Justice Department attorney, Chad Readler, previously defended the president's executive order as an attempt to use his "bully pulpit" to "encourage communities and states to comply with the law."
Readler also said the order applied to only three Justice Department and Homeland Security grants that would affect less than $1 million for Santa Clara County and possibly no money for San Francisco.
But the judge said the executive order was written broadly to reach all federal grants and potentially jeopardized hundreds of millions of dollars in funding to San Francisco and Santa Clara.
He cited comments by the president and Attorney General Jeff Sessions as evidence of the order's scope and said the president himself had called it a "weapon" to use against recalcitrant cities.
The government hasn't cut off any money yet or declared any communities to be sanctuary cities. But the Justice Department sent letters last week advising communities to prove they are in compliance. California was informed it could lose $18.2 million.
"Sanctuary cities" is a loosely defined term for jurisdictions that don't comply with immigration authorities.
The Trump administration argued that the executive order applied narrowly to cities that forbid officials from reporting people's immigration status to federal authorities. But Orrick said it could also be construed to apply to cities that refuse to hold jail inmates for immigration authorities.
The Trump administration says sanctuary cities allow dangerous criminals back on the street and that the order is needed to keep the country safe. San Francisco and other sanctuary cities say turning local police into immigration officers erodes the trust that is needed to get people to report crime.
The order has also led to lawsuits by Seattle; two Massachusetts cities, Lawrence and Chelsea; and a third San Francisco Bay Area government, the city of Richmond. The San Francisco and Santa Clara County lawsuits were the first to get a hearing before a judge.
On Tuesday, mayors from several cities threatened with the loss of federal grants emerged from a meeting with Sessions saying they remain confused about how to prove their police are in compliance with immigration policies.
The sanctuary city order was among a flurry of immigration measures Trump signed after taking office in January, including a ban on travelers from seven Muslim-majority countries and a directive calling for a wall on the Mexican border.
A federal appeals court blocked the travel ban. The administration then revised it, but the new version also is stalled in court.
Associated Press writers Sadie Gurman and Julie Bykowicz in Washington contributed to this story.