Updated

The 9th Circuit Court of Appeals on Wednesday upheld an injunction barring the Trump administration from repurposing approximately $2.5 billion in Pentagon money to the Department of Homeland Security to build a border wall with Mexico, prompting the White House to promise an immediate appeal.

A divided three-judge panel on the appellate court agreed with a lower court ruling that prevented the government from tapping Defense Department counterdrug money to build high-priority sections of wall in Arizona and New Mexico.

In February, Trump ended a 35-day government shutdown after Congress gave him far less than he wanted. He then declared a national emergency that the White House said would free billions of dollars from the Pentagon.

In its ruling, the 9th Circuit panel noted that Section 8005 of the Department of Defense Appropriations Act of 2019 "authorizes the Secretary of Defense to transfer funds for military purposes if the Secretary determines that the transfer is 'for higher priority items, based on unforeseen military requirements' and 'the item for which funds are requested has [not] been denied by the Congress.'"

But according to the 2-1 majority on the appellate court panel, the "need for which the funds were reprogrammed was not 'unforeseen,' and it was an item for which funds were previously 'denied by Congress.'"

Additionally, the judges ruled, the Trump administration likely had violated the Appropriations Clause of the Constitution, which states that "No Money shall be drawn from the Treasury, but in Consequence of Appropriations made by Law.”

Army engineers install concertina wire on Nov. 5, 2018, on the Anzalduas International Bridge, Texas. (US Air Force photo by Airman First Class Daniel A. Hernandez)

The 9th Circuit's ruling was not a final judgment on the merits of the case, which may still be considered by the appellate court and Supreme Court. But the administration cannot build during the legal challenge.

"Congress and now two courts have said no to border wall funds. For the sake of our democracy and border communities, it’s time the president come to terms with the fact that America rejected his xenophobic wall — and move on," Dror Ladin, staff attorney with the American Civil Liberties Union’s National Security Project, who argued the case before the appeals court, said in a statement.

Wednesday's ruling followed a lawsuit brought by the ACLU on behalf of the Sierra Club and the Southern Border Communities Coalition (SBCC) -- parties that had more success than Democrats in Congress. In June, Washington, D.C., district court Judge Trevor McFadden threw out House Democrats' lawsuit seeking an injunction against President Trump's emergency border wall funding reallocation, saying that the matter is fundamentally a political dispute and that the politicians lack standing to make a legal case.

However, the Trump administration conceded that the ACLU and SBCC had standing because their clients, unlike House Democrats, had suffered "injuries from environmental harm."

"Today’s Ninth Circuit ruling upholds the basic notion that only Congress can appropriate funds," Gloria Smith, managing attorney at the Sierra Club, said in a separate statement. "We've seen the damage that the ever-expanding border wall has inflicted on communities and the environment for decades. Walls divide neighborhoods, worsen dangerous flooding, destroy lands and wildlife, and waste resources that should instead be used on the infrastructure border communities truly need."

Other border wall construction not using Pentagon funds remains unaffected by the ruling. U.S. Customs and Border Protection (CBP), in partnership with the Army Corps of Engineers, announced a new panel installation on an 11-mile section of wall within the Border Patrol's San Diego sector on Thursday. The CBP, which announced the project earlier this month, also said it would initiate a new border wall project in Tecate, Calif.

SHOCK FOOTAGE SHOWS MIGRANTS WALKING AROUND BORDER WALL TO ENTER THE U.S.

But the freeze imposed by U.S. District Judge Haywood Gilliam Jr. in May prevented work on two Pentagon-funded wall contracts — one spanning 46 miles in New Mexico and another covering five miles in Yuma, Ariz.

While the order applied only to those first-in-line projects, Gilliam made clear that he felt the ACLU and other groups were likely to prevail at trial in their argument that the president was ignoring Congress' wishes by diverting Defense Department money.

"Congress' '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. It is a feature of that system, and an essential one," the judge wrote.

Gilliam went a step further Friday by ruling definitively that the administration couldn't use Pentagon counterdrug money for the two projects covered in his May order or to replace 63 miles in the Border Patrol's Tucson, Ariz., sector and 15 miles in its El Centro, Calif., sector.

At stake is billions of dollars that would allow Trump to make progress on a major 2016 campaign promise heading into his race for a second term.

Trump declared a national emergency after losing a fight with the Democratic-led House that led to the 35-day shutdown. Congress agreed to spend nearly $1.4 billion on barriers in Texas' Rio Grande Valley, the busiest corridor for illegal crossings, which was well below the $5.7 billion the president requested.

Trump grudgingly accepted the money but declared the emergency to siphon money from other government accounts, finding up to $8.1 billion for wall construction. The money includes $3.6 billion from military construction funds, $2.5 billion from Defense Department counterdrug activities and $600 million from the Treasury Department's asset forfeiture fund.

Acting Defense Secretary Mark Esper has yet to approve transferring the military construction funds. The Treasury Department funds have so far survived legal challenges.

The president's adversaries say the emergency declaration was an illegal attempt to ignore Congress. The ACLU sued on behalf of the Sierra Club and the Southern Border Communities Coalition.

FILE - This March 2, 2019, file photo, shows a Customs and Border Control agent patrolling on the US side of a razor-wire-covered border wall along the Mexico east of Nogales, Ariz. (AP Photo/Charlie Riedel, File)

The administration said the U.S. needed emergency protection to fight drug smuggling. Its arguments did not mention illegal immigration or unprecedented numbers of Central American families seeking asylum at the U.S. border, which have dominated public attention in recent months.

Justice Department attorneys argued that the freeze on Pentagon funds showed a "fundamental misunderstanding of the federal appropriations process."

"The real separation-of-powers concern is the district court's intrusion into the budgeting process," they wrote.

The two sides argued before a three-judge panel in San Francisco on June 20, made up of Barack Obama appointee Michelle Friedland and George W. Bush appointees N. Randy Smith and Richard Clifton.

CLICK HERE TO GET THE FOX NEWS APP

The administration has awarded $2.8 billion in contracts for barriers covering 247 miles, with all but 17 miles of that to replace existing barriers not expand coverage. It is preparing for a flurry of construction that the president is already celebrating at campaign-style rallies.

Trump inherited barriers spanning 654 miles, or about one-third of the border with Mexico. Of the miles covered under Trump-awarded contracts, more than half is with Pentagon money.

Fox News' David Aaro, Bill Mears, and The Associated Press contributed to this report.