Washington (AFP) – The US Supreme Court on Friday ruled in favor of President Donald Trump, allowing him to proceed with plans to divert billions of dollars in Pentagon funds towards construction of his border wall with Mexico.

“Wow! Big VICTORY on the Wall,” Trump tweeted in reaction to the ruling. “Big WIN for Border Security and the Rule of Law!”

Trump declared a national emergency earlier this year in a bid to bypass Congress and obtain funding for his signature project, after the standoff led to the longest government shutdown in US history.

But about 20 US states along with rights and environmental groups and border communities are backing lawsuits that claim the emergency declaration violates the constitution.

Last May, a federal judge on the Ninth Circuit Court of Appeals ruled in their favor, issuing a temporary injunction against using Defense Department funds for wall construction.

On Friday, the Supreme Court overturned the lower court decision with a 5-4 ruling, writing that the government had “made a sufficient showing at this stage” that the groups did not have the standing to challenge the allocation of funds.

The ruling will allow Trump temporary access to some $2.5 billion for the project while the legal battles play out.

The American Civil Liberties Union (ACLU) immediately vowed to seek an expedited decision from the Ninth Circuit “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,” said Dror Ladin, attorney with the ACLU’s national security project.

Trump made the construction of a wall to stem illegal immigration from Latin America central to his successful 2016 campaign for the presidency.