LOS ANGELES — A federal judge in Northern California on Friday permanently blocked the Trump administration from using $2.5 billion in contested funding to build barriers along the United States’ southwestern border, dealing a blow to the White House’s efforts to fund a border wall without congressional approval.

Judge Haywood S. Gilliam Jr. of the United States District Court for the Northern District of California, who ruled at once on two pending lawsuits against the administration, stated President Trump’s efforts to shift Department of Defense funds toward the border project were “unlawful.”

The decision follows an earlier temporary injunction, issued last month, in which Judge Gilliam said the White House’s efforts did not “square with fundamental separation of powers principles dating back to the earliest days of our Republic.”

The White House had sought to direct $2.5 billion from counterdrug programs in the Department of Defense toward building the wall.