After a federal judge blocked his attempt to build key sections of his border wall with money secured under his declaration of a national emergency, Donald Trump criticised the justice for being an “activist” appointed by Barack Obama.

In what may prove a temporary setback to the president, US district judge Haywood Gilliam Jr’s order, issued on Friday, stopped work from beginning on two Pentagon-funded projects: a section of border barrier spanning 46 miles in New Mexico and another covering five miles in Yuma, Arizona.

Trump inherited barriers covering 654 miles, or about one-third of the border with Mexico, the country he insisted during his 2016 campaign would pay for a border wall but which flatly rejected the idea.

Of the 244 miles of barrier covered by contracts awarded so far, more than half is covered by Department of Defense money. All but 14 miles awarded so far are to replace existing barriers, not extend coverage. Ignoring that, Trump has regularly claimed his wall is being built.

On Saturday, from Japan, Trump pledged to file an expedited appeal.

Echoing other controversial attacks on judges, he tweeted: “Another activist Obama appointed judge has just ruled against us on a section of the Southern Wall that is already under construction. This is a ruling against Border Security and in favor of crime, drugs and human trafficking. We are asking for an expedited appeal!”

While Gilliam’s order applied only to two projects, the judge made clear he felt the challengers were likely to prevail at trial on their argument that Trump was wrongly ignoring Congress’s wishes by diverting defense department money.

“Congress’s ‘absolute’ control over federal expenditures, even when that control may frustrate the desires of the executive branch regarding initiatives it views as important, is not a bug in our constitutional system,” the judge wrote in a 56-page opinion.

“It is a feature of that system, and an essential one.”

It was not a total defeat for Trump. Gilliam, who is based in Oakland, rejected a request by California and 19 other states to prevent the diversion of hundreds of millions of dollars in Treasury asset forfeiture funds to wall construction, in part because he felt they were unlikely to prevail on arguments that the administration skirted environmental impact reviews.

The administration faces several lawsuits over the emergency declaration but only one other seeks to block construction. A judge in Washington DC on Thursday heard arguments on a challenge brought by the House of Representatives that says the money-shifting violates the constitution.

In February, Trump declared a national emergency after losing a fight with the Democratic-led House that led to a 35-day government shutdown. As a compromise, Congress set aside $1.375bn to extend or replace existing border barriers in the Rio Grande Valley, the busiest corridor for illegal crossings.

Trump grudgingly accepted the money, then declared the national emergency in order to siphon money from other government accounts, identifying up to $8.1bn. The funds include $3.6bn from military construction funds, $2.5bn from defense department counter-drug activities and $600m from the treasury asset forfeiture fund.

The Pentagon has transferred the counter-drug money. Patrick Shanahan, the acting defense secretary, is expected to decide soon whether to transfer the military funds. Gilliam’s ruling gives a green light, at least for now, for the administration to tap the treasury funds.

Trump’s adversaries say the emergency declaration was an illegal attempt to ignore Congress. The administration says Trump was protecting national security as unprecedented numbers of asylum-seeking families arrive at the southern border.