The Supreme Court late Friday cleared the way for the Trump administration to use Defense Department counter-drug money to build a portion of the planned wall along the border with Mexico.

By a 5-4 vote, the court lifted a stay imposed in late May by a federal judge in California that blocked the use of $2.5 billion in Pentagon counter-drug program money to build more than 100 miles of border wall, a project announced as part of President Donald Trump's declaration of a national emergency. The judge had said that only Congress could approve such a transfer.

The Supreme Court's brief order Friday said only that the groups opposed to the wall did not have the proper legal status to challenge the transfer in court. The Sierra Club, in filing a lawsuit over the plan, said the construction would produce environmental harm.

Trump hailed the court's decision on Friday night, tweeting: "Wow! Big VICTORY on the Wall. The United States Supreme Court overturns lower court injunction, allows Southern Border Wall to proceed. Big WIN for Border Security and the Rule of Law!"

Wow! Big VICTORY on the Wall. The United States Supreme Court overturns lower court injunction, allows Southern Border Wall to proceed. Big WIN for Border Security and the Rule of Law! — Donald J. Trump (@realDonaldTrump) July 26, 2019

The Justice Department had urged the Supreme Court two weeks ago to act on its request by July 26. It said the Defense Department would not have authority to transfer the money after the fiscal year ends Sept. 30. Given how long it takes to go through the contracting process, the government said, a prompt answer was necessary.

Justices Ruth Bader Ginsburg, Sonia Sotomayor and Elena Kagan said they would have left the lower court's stay in place. Justice Stephen Breyer said he would have favored a middle ground, allowing the government to prepare the necessary contracts but maintain a hold on actual construction.

The American Civil Liberties Union decried Friday's ruling, vowing to continue to fight to block the use of military funds. The ACLU represents the Sierra Club and Southern Border Communities Coalition in the fight against the wall.

“This is not over. We will be asking the federal appeals court to expedite the ongoing appeals proceeding to halt the irreversible and imminent damage from Trump's border wall. Border communities, the environment, and our Constitution’s separation of powers will be permanently harmed should Trump get away with pillaging military funds for a xenophobic border wall Congress denied,” Dror Ladin, staff attorney with the ACLU’s National Security Project, said in a statement Friday night.

Download the NBC News app for breaking news and politics

The president has been fighting for funding for the wall for months. Congress declined to approve the billions requested by the president earlier this year, which led to a partial shutdown of the federal government for 35 days — the longest in history.

Trump in February declared a national emergency that would require taking money from the Pentagon's budget for a wall. The emergency declaration set up a battle for power of the purse between the White House and Congress.