A federal judge has blocked Donald Trump from building sections of his long-sought border wall with money secured under his declaration of a national emergency.

On Friday, the US district judge Haywood Gilliam Jr put an immediate halt to the administration’s efforts to redirect military-designated funds for wall construction. His order applies to two projects, scheduled to begin as early as Saturday, to replace 51 miles of fence in two areas on the Mexican border.

The order blocks the use of $1bn from the Department of Defense in Arizona and Texas, out of $6.7bn the Trump administration said it planned to direct toward building the wall.

Gilliam issued the ruling after hearing arguments last week in two cases. California and 19 other states brought one lawsuit; the Sierra Club and a coalition of communities along the border brought the other. His ruling was the first of several lawsuits against Trump’s controversial decision to bypass the normal appropriations process to pay for his long-sought wall.

“The position that when Congress declines the executive’s request to appropriate funds, the executive nonetheless may simply find a way to spend those funds ‘without Congress’ does not square with fundamental separation of powers principles dating back to the earliest days of our Republic,” the judge wrote in granting a temporary injunction to stop construction.

At stake is funding that would allow Trump to make progress in a signature campaign promise heading into his campaign for a second term.

Trump declared a national emergency in February after losing a fight with the Democratic-led House over fully paying for the wall that led to a 35-day government shutdown. As a compromise on border and immigration enforcement, Congress set aside $1.375bn to extend or replace existing barriers in Texas’s Rio Grande Valley, the busiest corridor for illegal crossings.

Trump grudgingly accepted the money, but he declared the emergency to siphon money from other government accounts because he wanted to spend $8bn on wall construction. The funds include $3.6bn from military construction funds, $2.5bn from defense department counterdrug activities and $600m from the treasury department’s asset forfeiture fund.

The president’s adversaries say the emergency declaration was an illegal attempt to ignore Congress, which authorized far less wall spending than Trump wanted.

A child looks through the border wall in Mexicali, Mexico. Photograph: Carlos Jasso/Reuters

“We welcome the court’s decision to block Trump’s attempts to sidestep Congress to build deadly walls that would hurt communities living at the border, endanger wildlife, and have damaging impacts on the environment,” said Andrea Guerrero, a member of the Southern Border Communities Coalition.

The administration said Trump was protecting national security as unprecedented numbers of Central American asylum-seeking families arrive at the US border.

The courtroom showdowns come amid a flurry of activity to accelerate wall construction.

Kenneth Rapuano, an assistant secretary of defense, said in a court filing last month that work on the highest-priority, Pentagon-funded projects could begin as soon as Saturday. The defense department has transferred $2.5bn to border wall coffers. Patrick Shanahan, the acting defense secretary, is expected to decide soon whether to transfer an additional $3.6bn.

Associated Press and Reuters contributed to this report