MIAMI -- Former U.S. president Donald Trump pleaded not guilty on Tuesday to federal criminal charges that he unlawfully kept national-security documents when he left office and lied to officials who sought to recover them.

Trump's plea, entered before U.S. Magistrate Judge Jonathan Goodman in a federal court in Miami, sets up a legal battle likely to play out over coming months as he campaigns to win back the presidency in a November 2024 election. Experts say it could be a year or more before a trial takes place.

Trump was allowed to leave court without conditions or travel restrictions and no cash bond was required. Goodman ruled that Trump was not allowed to communicate with potential witnesses in the case.

Trump's former aide Walt Nauta, who is also charged in the case, appeared in court alongside Trump but will not have to enter a plea until June 27 because he does not have a local lawyer. He, too, was released without having to post bond and was ordered not to talk to other witnesses.

Supporters chanted "We love Trump" as his motorcade departed the courthouse at 3:55 p.m. EDT (1955 GMT), roughly two hours after it arrived.

It was the second courtroom visit for Trump in recent months. In April, he pleaded not guilty to state charges in New York stemming from a hush-money payment to a porn star.

Trump is the first former president to be charged with federal crimes.

Authorities had prepared for possible violence, recalling the Jan. 6, 2021, attack on the U.S. Capitol, but Miami Mayor Francis Suarez told reporters that there had not been any security problems.

Trump has repeatedly proclaimed his innocence and accuses Democratic President Joe Biden's administration of targeting him. He called Special Counsel Jack Smith, who is leading the prosecution, a "Trump hater" on social media on Tuesday.

"ONE OF THE SADDEST DAYS IN THE HISTORY OF OUR COUNTRY. WE ARE A NATION IN DECLINE!!!" Trump wrote on his Truth Social platform shortly before his motorcade left the Trump Doral hotel for the courthouse.

Smith accuses Trump of risking national secrets by taking thousands of sensitive papers with him when he left the White House in January 2021 and storing them in a haphazard manner at his Mar-a-Lago Florida estate and his New Jersey golf club, according to a grand jury indictment released last week.

Photos included in the indictment show boxes of documents stored on a ballroom stage, in a bathroom and strewn across a storage-room floor.

Those records included information about the secretive U.S. nuclear program and potential vulnerabilities in the event of an attack, the indictment said.

The 37-count indictment alleges Trump lied to officials who tried to get them back.

The indictment also alleges Trump conspired with Nauta to keep classified documents and hide them from a federal grand jury. Nauta has worked for Trump at the White House and at Mar-a-Lago.

Donald Trump enters plea

REPUBLICAN VOTERS, RIVALS LINE UP BEHIND TRUMP

Recent events have not dented Trump's hopes of returning to the White House. After his arraignment Trump was due to fly from Miami to his New Jersey golf club, where he was scheduled to speak.

Nor have Trump's legal woes hurt his standing with Republican voters.

A Reuters/Ipsos poll released on Monday showed Trump still led rivals for the Republican nomination for the 2024 presidential election by a wide margin, and 81% of Republican voters viewed the charges as politically motivated.

Most of Trump's Republican rivals for the nomination have lined up behind him and accused the FBI of political bias, in a sharp turn from the party's traditional support for law enforcement.

Vivek Ramaswamy, one of those candidates, said outside the Miami courthouse that he would pardon Trump if he were elected.

ESPIONAGE ACT CITED IN CHARGES AGAINST TRUMP

Trump faces charges that include violations of the Espionage Act, which criminalizes unauthorized possession of defence information, and conspiracy to obstruct justice, which carries a maximum sentence of 20 years in prison.

That is the maximum sentence he faces, as he would serve any sentences concurrently if convicted.

Legal experts say the evidence amounts to a strong case, and Smith has said Trump, who will turn 77 on Wednesday, will have a "speedy" trial.

The judge assigned to the case, Aileen Cannon, was appointed by Trump in 2020 and issued a ruling in his favour during the investigation last year that was reversed on appeal. Goodman, the magistrate judge who conducted Tuesday's hearing, is not expected to play an ongoing role in the case.

Experts say the complexities of handling classified evidence and legal manoeuvring by Trump's lawyers could delay a trial by more than a year.

In the meantime, Trump is free to campaign for the presidency and could take office even if he were to be found guilty.

Trump accuses Biden of orchestrating the federal case to undermine his campaign. Biden has kept his distance from the case and declines to comment on it.

In his first presidential run in 2016, Trump called for imprisoning Democratic rival Hillary Clinton for using private email while serving as secretary of state, leading to chants of "lock her up" at campaign rallies. Then-FBI Director James Comey criticized Clinton for carelessness but did not recommend criminal charges.

(Additional reporting by Rami Ayyub, Sarah N. Lynch, Susan Heavey, Julia Harte, Tyler Clifford, Doina Chiacu and Luc Cohen; Writing by Andy Sullivan; Editing by Howard Goller)