A US judge has permanently blocked a presidential order that would have cut funding from US cities refusing to co-operate with immigration officials.
The California judge, who temporarily blocked the order in April, ruled that it was a violation of constitutional rights and separation of powers.
The decision was in response to a lawsuit filed by city of San Francisco and Santa Clara County.
It is considered a blow to Mr Trump’s crackdown on illegal immigration.
US District Judge William Orrick said on Monday the executive order was “unconstitutional on its face”.
“The Constitution vests the spending powers in Congress, not the President, so the Executive Order cannot constitutionally place new conditions on federal funds,” he wrote.
“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 executive order was issued just days after Mr Trump took office in January.
It sought to withhold funds from cities that would not cooperate with federal immigration requests to turn over any individual arrested for a crime who are suspected of entering the US illegally.
Dozens of municipalities, including New York, Los Angeles and Chicago, have joined the sanctuary movement.
San Francisco and Santa Clara County had argued that they would lose billions of dollars in federal grant funding if the president was allowed to enforce the order.
Department of Justice spokesman Devin O’Malley said in a statement late on Monday that the 9th US Circuit Court of Appeals had “exceeded its authority today when it barred the President from instructing his cabinet members to enforce existing law”.
“The Justice Department will vindicate the President’s lawful authority to direct the executive branch,” he added.
The department has already appealed Judge Orrick’s ruling in April.
San Francisco City Attorney Dennis Herrera called the ruling “a victory for the American people and the rule of law”.
“No one is above the law, including the president. President Trump might be able to tweet whatever comes to mind, but he can’t grant himself new authority because he feels like it,” he said in a statement.
Mr Trump has yet to comment on the final ruling.
Over the summer when the order was temporarily blocked, he tweeted that it was “ridiculous”.
The White House claimed at the time that the judge had given a “gift” to gangs that put “thousands of innocent lives at risk”.
Chicago also sued the federal government in August over the Justice Department’s threats to cut funding. A federal judge issued a preliminary injunction blocking the US government from withholding public-safety grants.