WASHINGTON — President Donald Trump's accounting firm must turn over eight years of the president's tax returns to a grand jury in New York, a federal judge ruled Monday.

Trump immediately appealed. A federal appeals court agreed to temporarily delay enforcing the lower court judge's decision while that case goes forward, which means the grand jury and state prosecutors in New York won't get Trump's tax returns just yet.

US District Judge Victor Marrero dismissed Trump's lawsuit challenging a grand jury subpoena issued by New York District Attorney Cyrus Vance. He wrote that Trump's argument for complete presidential immunity from a criminal investigation was "repugnant to the nation's governmental structure and constitutional value."

"Bared to its core, the proposition the President advances reduces to the very notion that the Founders rejected at the inception of the Republic, and that the Supreme Court has since unequivocally repudiated: that a constitutional domain exists in this country in which not only the President, but, derivatively, relatives and persons and business entities associated with him in potentially unlawful private activities, are in fact above the law," Marrero wrote.

The district attorney's office had agreed not to enforce the subpoena until 1 p.m. on Monday while the two sides waited for the judge to rule. Trump's lawyers appealed Marrero's decision to the US Court of Appeals for the 2nd Circuit immediately after the ruling came down Monday morning.

The decision is the latest setback for Trump in his bid to stop his opponents in Congress and at the state level from getting his financial records. Federal judges have previously rejected Trump's challenges to congressional subpoenas to his accounting firm and banks; those decisions are already pending before appeals courts.

In the latest case, filed in the US District Court for the Southern District of New York, Trump challenged a grand jury subpoena issued to Trump's longtime accounting firm, Mazars USA LLP, in August, for the president's tax returns going back to 2011. Trump is represented in the case by his personal attorneys — the judge questioned whether Trump could argue for presidential immunity under those circumstances — but the Justice Department last week filed a letter in support of Trump arguing the court should consider the case.

Marrero dismissed Trump's lawsuit based on a legal doctrine known as "abstention," in which a federal judge in rare circumstances can decline to exercise jurisdiction over a case if it would interfere with certain government functions at the state level, such as state criminal prosecutions. The judge wrote that an "important state interest is implicated" in Trump's case.

In a footnote, Marrero wrote that he was "sensitive" to Trump's argument that Monday's ruling could "embolden" state officials to investigate presidents in the future purely for political gain. But he found that argument wasn't strong enough to stop the subpoena at issue, since it was directed to a third party — Trump's accounting firm — as part of a "broad investigation" that could ultimately target other people besides the president.

The judge rejected Trump's argument that Vance's office was pursuing the grand jury subpoena in "bad faith" because it mirrored a subpoena that House Democrats had also issued to Mazars, noting the breadth of the New York investigation.

According to the New York district attorney's office, the investigation relates in part to hush money payments made to two women who claimed to have had affairs with Trump, Stormy Daniels and Karen McDougal, and the involvement of the Trump Organization in orchestrating those payments.

The judge delved into Trump's presidential immunity argument, in case the 2nd Circuit disagreed with his decision to abstain from exercising his jurisdiction over the case in the first place.

Courts in the past have rejected arguments made by sitting presidents that they are completely immune from civil lawsuits and criminal investigations. The US Supreme Court ruled in 1974 that President Richard Nixon was not immune from a subpoena for recordings and documents. In 1997, the justices ruled that President Bill Clinton wasn't immune from a civil lawsuit filed against him related to events that happened before he took office.

The Justice Department has taken the position that a sitting president cannot be indicted, but that isn't binding on judges or state prosecutors. Marrero wrote that he rejected the Justice Department's position, noting that the Supreme Court had never directly weighed in, that it only addressed federal prosecutions — the president can exercise authority over the Justice Department and hand out pardons for federal offenses, but doesn't have that same power at the state level — and that it was developed in the "abstract" and not tied to a "real case presenting real facts."

The Justice Department's position treated all criminal investigations as the same in arguing that such investigation could interfere with the president exercising his official duties, Marrero wrote. But not every case "would raise the grim specters" put forward by the government, he wrote. A murder charge might present those "extraordinary circumstances," the judge mused, but a charge of failing to pay state taxes or responding to a subpoena related to third parties might not.

"[T]he President's claim of absolute immunity conceivably could enable the guilty to go free, and deprive the innocent of an opportunity to resolve serious accusations in a court of law," Marrero wrote.

Trump's personal attorney William Consovoy did not immediately return a request for comment. Danny Frost, a spokesperson for the district attorney's office, declined to comment.