The Supreme Court on Friday allowed President Donald Trump to transfer billions of dollars of military funding in order to construct hundreds of miles of wall along the U.S.-Mexico border in Arizona, California and New Mexico.

The funding transfer was challenged by the environmental nonprofit Sierra Club and a border area advocacy group in February, shortly after Trump announced he would move forward with plans to construct the wall despite opposition from Congress.

Trump praised the highest court’s decision in a tweet Friday, calling it a victory for “border security and the rule of law.”

The fight over border wall funding sparked the longest federal government shutdown in history. Congress ultimately allocated about $1.4 billion in border wall funding to be deployed in Texas, far short of the $6 billion the administration sought.

Trump subsequently declared a national emergency at the southern border and claimed that the declaration would make available the full $6 billion, including $2.5 billion transferred from the Department of Defense.

Sierra Club and the Southern Border Communities Coalition challenged the $2.5 billion transfer, alleging that construction of the wall would cause environmental harm and permit the president to spend money denied to him by lawmakers.

A federal district court in California blocked the funds' transfer in June. District Judge Haywood Gillium wrote that Congress “struck what it considered to be the proper balance — in the public’s interest — by making available only $1.375 billion in funding.”

The Justice Department asked the 9th U.S. Circuit Court of Appeals to halt the lower court’s order, but it refused to do so, voting to reject the administration in early July by a vote of 2-1.

On July 12, the administration brought its case to the Supreme Court. In a filing with the justices, Solicitor General Noel Francisco argued that the wall funding is necessary “to stanch the flow of illegal drugs across the southern border.”

Those concerns outweigh “whatever aesthetic and recreational injuries respondents and their members may incur” if the wall is constructed, Francisco wrote.