A judge has blocked US President Donald Trump's executive order that withheld funds from "sanctuary cities", striking another blow to his anti-immigration agenda.

Sanctuary cities are areas that have declined to cooperate in enforcement of federal immigration laws in order to protect their foreign but often undocumented populations.

Trump vowed to deprive those areas of federal funding until they complied and did so with his executive-order powers, however US District Judge William Orrick III, on Tuesday (25 April), placed an injunction on the order.

The decision comes after San Francisco and Santa Clara County both sued Trump in February, arguing that the executive order was unconstitutional and that the funds deprived went beyond law enforcement budgets.

In his ruling, Orrick sided with the two California counties and said that the language of the executive order made 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," Orrick wrote.

He described how Trump called the order a "weapon" against jurisdictions which disagreed 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," he added.

Orrick's ruling is the second setback to emerge from Trump on Tuesday as reports emerged he will delay funding for his border wall with Mexico until the autumn of 2017 to avoid a government shutdown.

However, Trump immediately hit back via Twitter, stating: "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."

Earlier in the year, federal judges in the courts also suspended Trump's executive orders restricting travel from several Muslim-majority countries into the US. The government has appealed that decision.