Dealing a new setback to the government's pledged crackdown on undocumented immigrants, Judge William Orrick of the San Francisco district court issued a preliminary injunction to block any attempt to implement President Donald Trump's January 25 order to cut funds to such cities.
Orrick said the order, one of the first Trump issued after become president, was against the public interest and did not stand up under the constitution.
But Orrick's ruling allowed the Department of Justice to follow through with threats made to nine cities last week to cut specific program grants if the cities did not adequately cooperate with federal immigration officers.
That ensured that tensions between the federal government and hundreds of cities and counties around the country over the Trump crackdown will continue.
WATCH: Sessions vows to crack down on sanctuary cities
Trump's order unconstitutional
Orrick accepted the arguments of San Francisco city and Santa Clara County, which includes San Jose and Silicon Valley, that the president did not have power to hold back any funds to cities that offer some protections to illegal immigrants.
Trump's order threatened the transfer of some $1.2 billion for San Francisco, and $1.7 billion to Santa Clara County.
Orrick noted that the government's lawyers sought to avoid arguing the issue of whether Washington has the right to take such steps.
Instead, they weakly challenged the right of San Francisco and Santa Clara County to fight the order because neither had been formally declared "sanctuary jurisdictions" -- a phrase that remains vague in the law.
But the judge said the key issue was still Trump's repeated statements that funding is a "weapon" to use against cities that resist his policies. That demonstrates the government's intent, he said, and that is unconstitutional.
"The Constitution vests the spending powers in Congress, not the president, so the order cannot constitutionally place new conditions on federal funds," he said.
Related reading
'Better you than me,' Trump tells record-breaking astronaut
Justice Department, mayors still at odds
But as a meeting in Washington Tuesday between a group of major-city mayors and Attorney General Jeff Sessions showed, the two sides remain at odds over Trump's election promise to expel some 11.3 million immigrants without legal residency.
Last Friday, Sessions lashed out at sanctuary cities for allowing illegal immigrants who are violent criminals to go free, blaming such policies for the growth of the MS-13 gang across the country.
The Justice Department sent warnings to nine cities including Chicago, New Orleans,and Philadelphia, that they would lose certain grants that are tied to meeting Justice Department rules on cooperating with federal law enforcement and immigration officials.
WATCH: Spicer confirms Trump, Turnbull meeting
Compliance with those rules, Sessions said after Tuesday's meeting, "is the minimum the American people should expect. We want all jurisdictions to enthusiastically support the laws of the United States that require the removal of criminal aliens, as many jurisdictions already do."
But mayors who were in the meeting said federal policy remains unclear and inconsistent, and complained the government is telling them to deploy local law enforcement officers to enforce federal immigration laws.
"We are going to continue to push back on any suggestion that we deemphasize or deprioritize those serious criminals in our community," said Jorge Elorza, mayor of Providence, Rhode Island.
"None of this discussion would be necessary if Congress and the president would enact comprehensive immigration reform, which is long overdue," said New Orleans Mayor Mitch Landrieu.
WATCH: Trump congratulates astronaut on new space record