WASHINGTON — President Donald Trump's declaration of a national emergency to divert billions of dollars from the Pentagon for a border wall faced its first courtroom test on Friday.

Federal District Court Judge Haywood Gilliam in Oakland, Calif., seemed skeptical as Justice Department attorneys defended the president's action. The judge directed his most pointed questions at government lawyers, but he did not announce a ruling at the end of a nearly three-hour hearing.

The Sierra Club and a group of southern U.S. communities sought an order to immediately block the plan, which was announced in February after Congress declined to approve the billions requested by the president. They asked for a nationwide order to stop any construction paid for by money under the Trump's emergency order.

"This case is best summed up by a statement from the White House chief of staff," said Doug Letter, appearing on behalf of the U.S. House of Representatives, which filed a friend of court brief. "Mr. (Mick) Mulvaney said basically, 'We're going to build this wall, and we'll do it with Congress or without it.' The president decided Congress is just a nuisance so he'll just do it on his own. And that is unconstitutional."

Operating under its emergency declaration, the administration put together a plan for spending about $6 billion dollars, mostly from the Pentagon budget. Acting Defense Secretary Patrick Shanahan has told Congress the money would build 256 miles of border, with 63 of them completed by the end of the year.

Dror Ladin of the ACLU, representing the Sierra Club and the other challengers, said Congress approved only $1.375 billion for border wall construction and only for projects in the Rio Grande Valley.

"Congress imposed restrictions on the location, scope and speed with which any wall could lawfully be built. Instead of abiding by that law, the president immediately announced he would violate its restrictions," Ladin said.

Plans to build segments of the wall in New Mexico and Arizona are outside of what Congress approved, he said.

In defending the emergency declaration, Justice Department lawyer John Burnham said the only limitation imposed by Congress was to say how much could be spent from money it appropriated for wall segments in Texas.

"Congress did not say or even suggest that the Defense Department could not use its funds for border barrier projects elsewhere," Burnham said. "If Congress wanted to restrict that authority, it could have done so."

The challengers also said that under a law the president invoked in his emergency declaration, the money from the Pentagon can be used only to support activities of the military. "There is no emergency requiring the use of the armed forces along the U.S.-Mexico border," the ACLU said in its court filings.

But Burnham said the law gives the government much wider latitude to use that money.

The Sierra Club's request for a nationwide injunction to stop the work was the first to be heard by a judge. Supported by its Democratic majority, the House of Representatives has separately filed a lawsuit of its own to challenge the border wall emergency declaration. A federal judge in Washington holds a hearing in that case on Thursday.

Shortly after declaring a national emergency, Trump predicted that he would not fare well in the cases filed in California.

"They will sue us in the 9th Circuit," he said. "We will possibly get a bad ruling, and then we'll get another bad ruling, and then we'll end up in the Supreme Court."