FILE - In this Friday April 5, 2019, file photo, President Donald Trump speaks as he visits a new section of the border wall with Mexico in Calexico, Calif. A federal judge in California has blocked Trump from building sections of his long-sought border wall with money secured under his declaration of a national emergency. U.S. District Judge Haywood Gilliam Jr. on Friday, May 24, 2019, immediately halted the administration's efforts to redirect military-designated funds to build sections of wall on the Mexican border. (AP Photo/Jacquelyn Martin, File)

SAN FRANCISCO (AP) — A federal judge on Friday blocked President Donald Trump from building key sections of his border wall with money secured under his declaration of a national emergency, delivering what may prove a temporary setback on one of his highest priorities.

U.S. District Judge Haywood Gilliam Jr.'s order prevents work from beginning on two of the highest-priority, Pentagon-funded wall projects — one spanning 46 miles (74 kilometers) in New Mexico and another covering 5 miles (8 kilometers) in Yuma, Arizona.

While the order applied only to those first-in-line projects, the judge made clear that he felt the challengers were likely to prevail at trial on their argument that the president was wrongly ignoring Congress' wishes by diverting Defense Department money.

"Congress's 'absolute' control over federal expenditures_even when that control may frustrate the desires of the Executive Branch regarding initiatives it views as important_is not a bug in our constitutional system. It is a feature of that system, and an essential one," he wrote in his 56-page opinion.

It wasn't a total defeat for the administration. Gilliam, an Oakland-based appointee of President Barack Obama, rejected a request by California and 19 other states to prevent the diversion of hundreds of millions of dollars in Treasury asset forfeiture funds to wall construction, in part because he felt they were unlikely to prevail on arguments that the administration skirted environmental impact reviews.

The delay may be temporary. The question for Gilliam was whether to allow construction with Defense and Treasury funds while the lawsuits brought by the American Civil Liberties Union and the state attorneys general were being considered. The cases still must be heard on their merits.

"This order is a win for our system of checks and balances, the rule of law, and border communities," said Dror Ladin, an attorney for the ACLU, which represented the Sierra Club and the Southern Border Communities Coalition.

The Justice Department did not immediately respond to a request for comment late Friday.

The administration faces several lawsuits over the emergency declaration but only one other seeks to block construction during the legal challenge. A judge in Washington, D.C., on Thursday heard arguments on a challenge brought by the U.S. House of Representatives that says the money shifting violates the constitution. The judge was weighing whether the lawmakers even had the ability to sue the president instead of working through political routes to resolve the bitter dispute.

At stake is billions of dollars that would allow Trump to make progress in a signature campaign promise heading into his campaign for a second term.

Trump declared a national emergency in February after losing a fight with the Democratic-led House that led to a 35-day government shutdown. As a compromise on border and immigration enforcement, Congress set aside $1.375 billion to extend or replace existing barriers in Texas' Rio Grande Valley, the busiest corridor for illegal crossings.

Trump grudgingly accepted the money, but then declared the national emergency to siphon money from other government accounts, identifying up to $8.1 billion for wall construction. The funds include $3.6 billion from military construction funds, $2.5 billion from Defense Department counterdrug activities and $600 million from the Treasury Department's asset forfeiture fund.

The Defense Department has already transferred the counterdrug money. Patrick Shanahan, the acting defense secretary, is expected to decide any day whether to transfer the military construction funds.

The president's adversaries say the emergency declaration was an illegal attempt to ignore Congress, which authorized far less wall spending than Trump wanted. The administration said Trump was protecting national security as unprecedented numbers of Central American asylum-seeking families arrive at the U.S. border.

The administration has awarded 11 wall contracts for a combined $2.76 billion — including three in the last two months that draw on Defense Department counterdrug money — and is preparing for a flurry of construction that the president is already celebrating at campaign-style rallies.

The Army Corps of Engineers recently announced several large contacts with Pentagon funding. Last month, SLSCO Ltd. of Galveston, Texas, won a $789 million award to replace 46 miles (74 kilometers) of barrier in New Mexico — the one that Gilliam blocked on Friday.

Last week, Southwest Valley Constructors of Albuquerque, New Mexico, won a $646 million award to replace 63 miles (101 kilometers) in the Border Patrol's Tucson, Arizona, sector, which Gilliam did not stop. Barnard Construction Co. of Bozeman, Montana, won a $141.8 million contract to replace 5 miles (8 kilometers) in Yuma that Gilliam blocked and 15 miles (24 kilometers) in El Centro, California, which he did not address.

Gilliam's ruling gives a green light — at least for now — for the administration to tap the Treasury funds, which it has said it plans to use to extend barriers in Rio Grande Valley.

California Attorney General Xavier Becerra, a Democrat and frequent Trump adversary, didn't comment directly on his defeat but congratulated the ACLU and its clients "in securing this critical victory for our states and communities."

Trump inherited barriers covering 654 miles (1,046 kilometers), or about one-third of the border with Mexico. Of the 244 miles (390 kilometers) in awarded contracts, more than half is with Pentagon money. All but 14 miles (22 kilometers) awarded so far are to replace existing barriers, not extend coverage.

___

Spagat reported from San Diego.

FILE - In this March 13, 2018, file photo, President Donald Trump holds a poster with photographs of the U.S. - Mexico border area as he reviews border wall prototypes in San Diego with Rodney Scott, the U.S. Border Patrol's San Diego sector chief. U.S. District Judge Haywood Gilliam Jr. has blocked President Donald Trump from building sections of his long-sought border wall with money secured under his declaration of a national emergency, Friday, May 24, 2019. (AP Photo/Evan Vucci, File)
FILE - In this Feb. 27, 2019, file photo, a border wall prototype falls during demolition at the border between Tijuana, Mexico, and San Diego. The government is demolishing eight prototypes of Donald Trump's prized border wall that instantly became powerful symbols of his presidency when they were built nine months after he took office. U.S. District Judge Haywood Gilliam Jr. has blocked President Donald Trump from building sections of his long-sought border wall with money secured under his declaration of a national emergency, Friday, May 24, 2019. (AP Photo/Gregory Bull, File)
FILE - In this Jan. 3, 2019, file photo, a migrant from Honduras passes a child to her father after he jumped the border wall to get into the U.S. side to San Diego, Calif., from Tijuana, Mexico. A federal judge is expected to decide Friday, May 24 whether to block the White House from spending billions of dollars to build a wall on the Mexican border with money secured under President Donald Trump's declaration of a national emergency. (AP Photo/Daniel Ochoa de Olza, File)
FILE - In this Nov. 21, 2018, file photo, two Honduran men pose as a photographer, at left, takes their picture after the group climbed the border wall separating Tijuana, Mexico, and San Diego, before climbing back down on the Mexican side, seen from San Diego. A federal judge is expected to decide Friday, May 24, 2019, whether to block the White House from spending billions of dollars to build a wall on the Mexican border with money secured under President Donald Trump's declaration of a national emergency. (AP Photo/Gregory Bull, File)
FILE - In this March 11, 2019, file photo, construction crews replace a section of the primary wall separating San Diego, above right, and Tijuana, Mexico, below left, seen from Tijuana, Mexico. President Donald Trump is reviving his border wall fight, preparing a new budget that will seek $8.6 billion for the U.S-Mexico barrier while imposing steep spending cuts to other domestic programs and setting the stage for another fiscal battle. A federal judge is expected to decide Friday, May 24, 2019, whether to block the White House from spending billions of dollars to build a wall on the Mexican border with money secured under President Donald Trump's declaration of a national emergency. (AP Photo/Gregory Bull, File)
FILE - In this Feb. 5, 2019 file photo, Border Patrol agent Vincent Pirro walks towards prototypes for a border wall in San Diego. Customs and Border Protection said Friday, Feb. 22, 2019, President Trump's eight border-wall prototypes will be torn down to make way for a secondary barrier separating California from Mexico. A federal judge is expected to decide Friday, May 24, 2019, whether to block the White House from spending billions of dollars to build a wall on the Mexican border with money secured under President Donald Trump's declaration of a national emergency (AP Photo/Gregory Bull, File)
FILE - In this April 5, 2019 file photo, President Donald Trump participates in a roundtable on immigration and border security at the U.S. Border Patrol Calexico Station in Calexico, Calif. A federal judge is expected to decide Friday, May 24, 2019 whether to block the White House from spending billions of dollars to build a wall on the Mexican border with money secured under President Donald Trump's declaration of a national emergency. California and 19 other states, along with environmentalists, civil liberties groups and communities along the border, are seeking a temporary injunction to halt construction plans.(AP Photo/Jacquelyn Martin, File)