“The president, however, acting through the White House counsel, has asserted that plaintiff, as a close personal adviser to the president, is immune from congressional process, and has instructed plaintiff not to appear and testify in response to the House’s subpoena,” the lawsuit said.

Administrations of both parties have taken that position. Steven A. Engel, the Trump-appointed head of the Justice Department’s Office of Legal Counsel, asserted in a 15-page legal opinion last summer that “Congress may not constitutionally compel the president’s senior advisers to testify about their official duties.”

Democrats have portrayed that legal theory as extreme and an act of obstruction by the Trump White House. They note that in 2008, a Federal District Court judge, John D. Bates, ruled that President George W. Bush’s former White House counsel, Harriet Miers, had no right to skip a hearing for which she had been subpoenaed. Judge Bates, a Bush appointee, said she had to show up — although she might still refuse to answer specific questions based on a claim of executive privilege.

The executive branch did not appeal the Miers ruling, and because no appeals court weighed in, Judge Bates’s opinion does not count as a controlling precedent for other disputes raising the same issue. That left the Obama administration, in a 2014 memo, free to take the position that Judge Bates had been wrong, and Mr. Engel echoed that logic in his memo as well.

Mr. McGahn defied the subpoena, citing the White House’s instructions, and in August, the House Judiciary Committee filed a lawsuit seeking a judicial ruling that the Justice Department is wrong, and an order requiring Mr. McGahn to testify. That litigation is not yet resolved.

Mr. Kupperman appears to be trying another route. Instead of defying his own subpoena and waiting to be sued, as Mr. McGahn did, he is going to court himself — suing both Congress and Mr. Trump for putting him in what he portrayed as an impossible position, and asking a judge to resolve the legal issue and tell him what to do.

Mr. Kupperman “is faced with irreconcilable commands by the legislative and executive branches of the government and, accordingly, seeks a declaratory judgment from this court as to whether he is lawfully obliged to comply with a subpoena issued by the House defendants demanding his testimony ‘pursuant to the House of Representatives’ impeachment inquiry,’ or he is lawfully obliged to abide by the assertion of immunity from congressional process made by the president in connection with the testimony sought from plaintiff,” it said.

Charlie Savage contributed reporting.