“The court removes any incentive for the executive branch to engage in the negotiation process seeking accommodation, all but assures future presidential stonewalling of Congress, and further impairs the House’s ability to perform its constitutional duties,” she wrote.

The ruling deflates a primary argument used by Mr. Trump’s defense team to question the legitimacy of the impeachment process. His lawyers insisted that the House should have pursued all of its legal avenues to secure testimony rather than charging the president with obstruction of Congress. But even as the impeachment trial unfolded, the Justice Department was arguing in the McGahn case that such lawsuits were invalid and, ultimately, the court adopted that reasoning.

If it stands, the ruling could halt a growing trend of Congress resorting to lawsuits to enforce its oversight powers in a polarized era when previous norms of bipartisan cooperation have broken down. It was once vanishingly rare for Congress and the executive branch to square off in court, but it has become increasingly common — especially in the past year, after Mr. Trump vowed to stonewall “all” oversight subpoenas by House Democrats.

Brianna Herlihy, a spokeswoman for the Justice Department, which was defending Mr. McGahn in court, said the Trump administration was “extremely pleased” with the ruling, calling it historic.

“Suits like this one are without precedent in our nation’s history and are inconsistent with the Constitution’s design,” she said. “The D.C. Circuit’s cogent opinion affirms this fundamental principle.”

Spokesmen for Speaker Nancy Pelosi of California and Representative Jerrold Nadler of New York, the chairman of the House Judiciary Committee, had no immediate comment. But it seemed likely that the House would appeal to the full appeals court to rehear the case.

Both judges in the majority were appointed by Republican presidents — Judge Griffith was appointed by George W. Bush and Judge Karen L. Henderson, who joined him in the decision, was appointed by George Bush. Judge Rogers was appointed by President Bill Clinton, a Democrat.