President Donald Trump tours the area around the U.S.-Mexico border wall in Calexico, California, U.S., April 5, 2019.

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. The funding had been frozen per lower courts' decisions.

The country's highest court voted 5-4 to allow the funding transfer, with Justices Ruth Bader Ginsburg, Sonia Sotomayor and Elena Kagan dissenting. Justice Stephen Breyer dissented in part, saying he would approve the transfer of funds but would not have construction of the wall begin just yet.

A brief order explaining the court's decision said the government "made a sufficient showing" that the groups challenging the decision did not have grounds to bring a lawsuit.

Trump praised the court's decision in a tweet Friday, calling it a victory for "border security and the rule of law."

tweet

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.

Breyer, in a written opinion published Friday, said construction of the border wall would "cause irreparable harm to the environment," but that denying the transfer of funding would constitute a final judgement on the matter. Breyer wrote:

"If we instead deny the stay, however, it is the Government that may be irreparably harmed. The Government has represented that, if it is unable to finalize the contracts by September 30, then the funds at issue will be returned to the Treasury and the injunction will have operated, in effect, as a final judgment. ... I can therefore find no justification for granting the stay in full, as the majority does."

—Reuters contributed to this report.

WATCH: We have to take Trump at his word on closing Mexico border, policy expert says