House Democrats are aggressively exploring a possible legal challenge should President Trump declare a national emergency to build a U.S.-Mexico border wall, scouring federal law and court precedents — including a recent attempt by a Republican-controlled House to undermine the Obama-era health-care law.

The preparation comes as leaders of both parties become increasingly convinced that Trump will see a national-emergency declaration as the only possible way to secure the billions of taxpayer dollars he is seeking to build the wall and end the three-week partial government shutdown, which has become the longest in U.S. history.

Trump on Friday said he “100 percent” had the power to build the wall — a project he previously said would be financed by Mexico — under emergency powers, but said he was “not going to do it so fast” and would give Congress more time to act.

But Democrats have moved quickly behind the scenes to defend against a possible emergency declaration, a step that members of both parties increasingly view as inevitable.

While Democratic lawmakers and lawyers are researching how to potentially undermine the move in the courts, according to House officials familiar with the effort, aides to Speaker Nancy Pelosi (D-Calif.) and staff members on several House committees are developing a parallel strategy to convince the public that an emergency declaration is unwarranted and would harm communities where previously funded projects were raided to pay for the wall.

“Look, an emergency cannot be whatever a president says an emergency is,” said Rep. Jamie B. Raskin (D-Md.), a House Judiciary Committee member and former law professor who has studied the issue in recent days. “If Congress gives President Trump a red light on his border wall, he cannot pretend that there is a green light existing in the administrative machinery of government. But this is a legal question, and we’re very happy to relocate it from the halls of Congress into the courts.”

Democrats are focusing on the courts in part because they are unlikely to have an effective legislative option for checking a Trump emergency declaration. Under the National Emergencies Act, which sets out procedures for their declaration and revocation, both chambers of Congress would have to pass a resolution overturning a presidentially declared emergency, then present it to Trump for his signature. Even if the GOP-controlled Senate joined House Democrats, Trump would presumably veto it.

While some Republicans have expressed queasiness over an emergency declaration, including Senate Judiciary Committee Chairman Charles E. Grassley (Iowa), others have been fully supportive. “There’s no question, it’s perfectly legal,” said Rep. Douglas A. Collins (Ga.), the top Republican on the House Judiciary Committee. “He has all the authority in the world to declare an emergency and use it for construction.”

Trump himself anticipated litigation Friday: “I’ll be sued, and it will be brought to the 9th Circuit . . . and we will probably lose there,” he said, referring to the San Francisco-based U.S. Court of Appeals for the 9th Circuit, where several of his policies have suffered losses.

While a presidential emergency declaration has not been squarely challenged in court since the NEA was passed in 1976, legal experts say that the House could have standing to sue, citing a 2015 case that offered clear parallels.

In that case, the then-GOP-led House sued the Obama administration over its effort to use federal money to reimburse health insurers for subsidies offered under the Affordable Care Act without an explicit congressional appropriation.

U.S. District Judge Rosemary Collyer in September 2015 allowed the suit to go forward, ruling that the House had standing to argue that its constitutional power to set federal spending had been violated.

“Neither the president nor his officers can authorize appropriations; the assent of the House of Representatives is required before any public moneys are spent,” Collyer wrote in the case brought against then-Health and Human Services Secretary Sylvia Mathews Burwell.

Laurence Tribe, a constitutional scholar at Harvard Law School, said in an email that the Burwell ruling “does indeed provide a strong argument the House could make to support its standing to sue President Trump if he were to carry out this threat to spend money pursuant to a declaration of national emergency.”

The ruling on standing is not binding, but Sam Berger, a senior adviser at the Center for American Progress who was a senior lawyer in the White House Office of Management and Budget in the Obama administration, said the Burwell ruling has direct relevance: “Both cases involve the same claim: the president spending money that Congress hasn’t authorized.”

Raskin said that the question of standing was “totally terra incognita” but that even if the House is sidelined, other parties could intervene: “If money that was programmed for Texas, Florida, Mississippi, and Puerto Rico for disaster relief is suddenly rechanneled to the wall, certainly state attorneys general in those states would have standing to go to court.”

Berger noted that anyone whose land is seized to build the wall — a state’s, an individual’s or a tribe’s — also could have standing to sue.

The analysts said that the House probably would have a good case on the merits if a judge found that it had standing to sue.

Tribe said the claim could be “structurally identical” to that in the Burwell case, arguing that Trump’s decision to spend money on an emergency basis that Congress has specifically rejected “flies in the face both of the Constitution’s separation of powers and of what Congress sought to prohibit in the National Emergencies Act.”

Berger said other statutes might govern how a president can shift construction funds between military and civilian Army Corps of Engineers projects. But those laws, he said, require the existence of a bona fide emergency necessitating the use of the military and previous congressional authorization for the project.

“Nothing gives the president the authority to turn the military into his personal construction company to build a wall,” he said.

Rep. Pramila Jayapal (D-Wash.), another House Judiciary Committee member, said that Democratic members and committee staffers were exploring multiple legal options but that a final decision would depend on precisely what action Trump ultimately takes — if any.

Lawmakers of both parties, she said, should ultimately be interested in preserving congressional powers against presidential overreach.

“It really diminishes what emergency powers can be used for if he uses it for a manufactured crisis that he created himself. . . . I think that gets us into very murky waters and dangerous waters down the road.”