Donald Trump’s accounting firm must hand over eight years of his tax returns to New York prosecutors, a US appeals court ruled on Monday in the latest setback for Trump in his attempts to keep his finances secret.

The ruling by the New York-based second US circuit court of appeals backed the ability of prosecutors to enforce a subpoena for the returns against accounting firm Mazars.

Jay Sekulow, a lawyer for Trump, said in a statement: “We will be taking this case to the supreme court.”

That will preclude the immediate release of the information.

Manhattan district attorney Cyrus R Vance Jr sought the records in an investigation that includes payments made to buy the silence of two women, adult film actor and director Stormy Daniels and model Karen McDougal, who claim they had affairs with the president before the 2016 election. Trump has denied them.

Vance has agreed not to enforce the subpoena while Trump petitions the supreme court. Under the agreement, Trump now has 10 business days to file that petition.

The highest court has a 5-4 conservative majority including two justices, Neil Gorsuch and Brett Kavanaugh, who were appointed by Trump.

Last month, a lower-court judge ruled that the president’s claim to immunity while in office was “repugnant”.

US district judge Victor Marrero in Manhattan described the immunity argument as “extraordinary” and “an overreach of executive power [that was] repugnant to the nation’s governmental structure and constitutional values”.

He added: “The court cannot square a vision of presidential immunity that would place the president above the law.”

On Monday, Sekulow added: “The issue raised in this case goes to the heart of our Republic. The constitutional issues are significant.”

In the written appeals court decision, the judges said they only decided whether a state prosecutor can demand the president’s personal financial records while he is in office.

The court did not consider whether the president is immune from indictment and prosecution while in office or whether the president may be ordered to produce documents in a state criminal proceeding.

“We hold that any presidential immunity from state criminal process does not bar the enforcement of such a subpoena,” wrote chief judge Robert A Katzmann.

Trump’s lawyers have said the investigation by Vance, a Democrat, is politically motivated. A spokesman for Vance declined to comment.

Since Richard Nixon, presidential candidates have released their tax records by precedent rather than legal compulsion.

Since announcing his run for the White House in 2015, Trump has often said he will release his information after the completion of an audit. An audit does not preclude the release of such information.

As well as attempts to obtain financial information, Trump faces an impeachment inquiry in the Democratic-led House, over his attempts to get Ukraine’s leader to investigate his political rivals.