The Trump administration cannot access $2.5 billion in military funding to construct portions of a wall along the U.S.-Mexico border, the U.S. District Court for Northern California ruled late Friday.

In the first of two lawsuits, Judge Haywood S. Gilliam Jr. ruled that President Donald Trump's Department of Defense, Department of Homeland Security and Department of the Treasury may not "construct a border barrier" along El Paso, Texas; Yuma, Arizona; and El Centro, California, sectors of the boundary "using funds reprogrammed by DoD," the judgement read. That suit was brought by Sierra Club and the Southern Border Communities Coalition (SBCC),

In the other suit, brought by California and New Mexico, the judge concluded that the administration's attempts to use military funds for a "border barrier construction" in the El Paso and El Centro sectors "is unlawful."

Gilliam's rulings were hailed by plaintiffs.

"Congress was clear in denying funds for Trump’s xenophobic obsession with a wasteful, harmful wall," Dror Ladin, staff attorney with the ACLU’s National Security Project who argued the case for the Sierra Club and SBCC, said in a statement late Friday.

"This decision upholds the basic principle that the president has no power to spend taxpayer money without Congress’ approval," he said.

California Attorney General Xavier Becerra said in a statement, "These rulings critically stop President Trump’s illegal money grab to divert $2.5 billion of unauthorized funding for his pet project."

"All President Trump has succeeded in building is a constitutional crisis, threatening immediate harm to our state," he said. "President Trump said he didn’t have to do this and that he would be unsuccessful in court. Today we proved that statement true."

The Department of Justice did not respond immediately to NBC News' request for comment.

The judge certified both cases for appeal, meaning that the Trump administration can take the matters to a higher court.

The rulings did not completely snuff out the Trump administration's arguments. In the case of the environmentalists' suit, the judge denied a request for a broader "declaratory judgment."

In the states' case, the judge similarly denied "broader declaratory judgment, and (2) a permanent injunction," according to the ruling.

When Congress did not authorize funding for a full-on wall, the president in February declared a national emergency that would require taking money from the Pentagon's budget for a wall. Trump made the move after Congress declined to approve the billions requested by the president. The federal government was partially shut down for 35 days — its longest in history — over Trump's demand for border wall funding.

The emergency declaration set up a battle for power of the purse between the White House and Congress.

On Friday, Gilliam ruled in both cases that the government did not prove that the Pentagon money was needed for "unforeseen military requirements."

In the environmentalists' suit the judge also agreed that the construction could impact "enjoyment of public land."