It is hard to overstate the gravity of the criminal indictment issued against Donald Trump late Thursday by a federal grand jury. For the first time, a former president has been charged with violating federal laws, laws that he swore to uphold just over six years ago. It is the first time a former leader of the executive branch has been charged with obstructing the very agencies he led, and the first time a former commander in chief has been charged with endangering national security by violating the Espionage Act.

The indictment, unsealed on Friday, accuses Mr. Trump of 37 crimes. The majority of them — 31 of the counts — are for willful retention of national defense information, each a violation of the Espionage Act. There is one count of conspiracy to obstruct justice, in which Mr. Trump is accused of conspiring with his personal aide, Walt Nauta, to hide classified documents from the F.B.I. and the grand jury investigating the case. The other charges involve withholding documents, corruptly concealing documents and making false statements to law enforcement authorities.

The potential prison sentences for Mr. Trump add up to as much as 420 years, even though conviction almost never results in the maximum sentence. But this indictment confronts the country with the harrowing prospect of a former president facing years behind bars, even as he runs to regain the White House.

Mr. Trump and his Republican allies are already trying to politicize the indictment, insisting that the charges issued by 23 randomly chosen residents of South Florida were an attempt by President Biden to demolish his rival. But the evidence compiled by the government is so substantial that it is clear the Justice Department had no choice but to indict.

The indictment says that Mr. Trump not only took from the White House classified documents that he was not authorized to possess but also that he showed them to visitors and political cronies at his country club. One of the documents involved a potential attack on another country, which The New York Times has reported was Iran. “Isn’t it amazing?” he asked one visitor, brandishing the document. During that conversation Mr. Trump acknowledged that he knew the document was “a secret,” the indictment said.

The details in the indictment make it clear that Mr. Trump knew that he was not authorized to keep national security secrets in his possession and that he played a cat-and-mouse game to conceal them from the F.B.I. and other federal officials. At one point he suggested his lawyer take some documents to his hotel room and “pluck” out anything really bad, the indictment says. “Wouldn’t it be better if we just told them we don’t have anything here?” he asked his lawyers. He added, “Well, look, isn’t it better if there are no documents?” Meanwhile, he instructed his lawyers to falsely inform federal investigators that they had cooperated fully.

With these actions, the former president demonstrated once again his contempt for the rule of law, his disregard for America’s national security and his mockery of the oath he took to support and defend the Constitution.

Mr. Trump walked out of the White House with details of the nuclear capabilities of the United States and a foreign government, descriptions of support for terrorist activities by a foreign country and communications with the leader of a foreign country. It is the willful retention of this material that led to the 31 charges of violating the Espionage Act, which makes it a crime if someone deliberately retains national defense material “and fails to deliver it to the officer or employee of the United States entitled to receive it.”

Mr. Trump’s recklessness in retaining and showing off military secrets is both arrogant and breathtaking. It put the lives of American soldiers at risk. These are some of the United States’ most closely guarded secrets — so sensitive that many top national-security officials can’t see them — and Mr. Trump treated them like a prize he had won at a carnival. These actions underscore, yet again, why he is unfit for public office.

What makes the spectacle all the more stunning is that it was entirely unnecessary. Had Mr. Trump responded to the many formal requests to return the wrongfully taken documents by apologizing and handing them over immediately, he would have avoided any confrontation with federal law enforcement. That’s what responsible public servants like Mr. Biden and former Vice President Mike Pence did when classified material was found among their papers.

The former president’s defenders rushed in to call it political persecution. “It is unconscionable for a President to indict the leading candidate opposing him,” wrote the House speaker, Kevin McCarthy, in a tweet before the indictment was unsealed, as if Mr. Biden had any involvement in these charges.

To make an accusation that a prosecution is a purely political act — one that will undermine the public’s faith in an independent judiciary — is a serious charge and requires at least some basis in fact before it is irresponsibly broadcast to the world. There is no support for that charge, because it requires ignoring two years of evidence painstakingly collected by nonpolitical law enforcement investigators. The Justice Department appears to have followed the basic processes and rules already in place to reach this decision. The public is now able to judge for itself whether the government has a serious case and whether it is actually the Republican critics who are the ones doing the instant politicizing.

And Mr. Trump will be afforded due process, including a trial by a jury of one’s peers and the right to appeal a guilty verdict — all the protections the Constitution guarantees.

The Justice Department’s role is to apply the law equally, without regard to the status or political affiliation of the accused lawbreaker. That’s what makes this indictment so necessary: Federal prosecutors have sought and won convictions in dozens of classified-document cases involving behavior less egregious than Mr. Trump’s. And that’s why the claims of a witch hunt are lamentable. Don’t take it from us; listen to Mr. Trump’s own former attorney general, Bill Barr.

“This says more about Trump than it does the Department of Justice,” Mr. Barr said on “CBS Mornings” on Tuesday. “He’s so egotistical that he has this penchant for conducting risky, reckless acts to show that he can sort of get away with it.” He added, “There’s no excuse for what he did here.”

It’s become common during the past eight tumultuous years to invoke the term “unprecedented” — a useful shorthand for Mr. Trump’s compulsion to upend established norms and blow past crucial democratic guardrails. But his unprecedented behavior should not obscure an equally important point, which is that the response to it has many precedents.

The United States has prosecuted dozens of former governors, cabinet members and lawmakers. These prosecutions are essential in reaffirming the principle that no one — and especially no political leader — is above the law. To fail to bring such a case is to make it more likely that other abuses of power will occur.