Mr. Trump’s lawyers sued to block the subpoena, writing that the criminal investigation of the president was unconstitutional. They asserted that presidents have such unique power and responsibility that they cannot be subject to the burden of investigations, especially from local prosecutors who may use the criminal process for political gain.

They pointed to impeachment as the correct way to address any potential wrongdoing by a president. Mr. Trump’s lawyers also have called the district attorney’s action an “effort to harass the president by obtaining and exposing his confidential financial information, not a legitimate attempt to enforce New York law.”

A spokesman for Mr. Vance said the office had no comment on the appeals court decision.

The immunity argument has never been tested in court. Federal prosecutors are barred from charging a sitting president with a crime because the Justice Department has decided that presidents have temporary immunity from prosecution while they are in office.

But that policy has not precluded investigations of the president. Mr. Trump and other sitting presidents have been the subjects of federal criminal investigations, and local prosecutors like Mr. Vance have not been bound by the policy.

On Oct. 7, Judge Victor Marrero of Federal District Court in Manhattan issued a 75-page opinion, rejecting Mr. Trump’s position.

Mr. Trump appealed to the Second Circuit, and in oral arguments last month, William S. Consovoy, a lawyer for Mr. Trump, told the panel, “We view the entire subpoena as an inappropriate fishing expedition not made in good faith.”

During the arguments, the president’s immunity claim seemed to crystallize when Judge Chin cited an audacious statement Mr. Trump once made — that he could stand on Fifth Avenue and shoot somebody, without being hurt politically.