A federal judge has ordered former President Donald Trump not to talk publicly about witness testimony, grand jury subpoenas and other “sensitive” evidence in the Justice Department’s prosecution of him in the 2020 election conspiracy case.

In an order issued Friday, U.S. District Judge Tanya Chutkan said Mr. Trump and his defense lawyers “shall not disclose sensitive materials or their contents directly or indirectly to anyone” beyond the defense team and potential witnesses in his upcoming trial.

The judge, an Obama appointee, gave Special Counsel Jack Smith a list of materials he can designate as “sensitive,” including documents containing “personally identifying information” of trial participants, materials obtained through sealed search warrants, transcripts of witness interviews and “materials obtained from other governmental entities.”

The order also directs that Mr. Trump, the front-runner for the 2024 GOP presidential nomination, “shall not copy or reproduce sensitive materials,” except for use by his legal team in the case.

During a two-hour hearing earlier Friday, Judge Chutkan said the former president’s First Amendment right to speak out on the case “is not absolute.” Mr. Smith’s office had requested a broader order barring the former president from discussing publicly aspects of the case.

The judge said Mr. Trump’s status as a candidate for the 2024 GOP presidential nomination doesn’t affect her decision.

“The fact that he is running a political campaign currently has to yield to the administration of justice, and if that means he can’t say exactly what he wants to say in a political speech, that is just how it’s going to have to be,” the judge said at a hearing. “I cannot, and I will not, factor into my decision what effect it will have on a political campaign for either side.”

The next hearing is scheduled for Aug. 28, when Judge Chutkan is expected to set a trial date.

The protective order sought by Mr. Smith became an early flashpoint in the case accusing the Republican of illegally scheming to subvert the will of voters and cling to power after he lost to Democrat Joe Biden in November 2020.

The former president’s lawyers said the request by Mr. Smith barring Mr. Trump from talking about the case was too broad and would violate Mr. Trump’s First Amendment rights. Trump lawyer John Lauro said the government’s “goal” was to “interfere with the campaign.”

 “I’m not going to accept that,” the judge replied. “I haven’t seen any evidence that it’s politically motivated.”’

She said Mr. Trump won’t be allowed to have any electronic devices “that could copy or reproduce” trial documents if he reviews such items alone. She also rejected the proposal by Mr. Trump’s team to share any witness interviews or transcripts with the public.

“I’m finding it very difficult to envision a former president engaged in a political campaign talking about witnesses who may not have the kind of protections that he has. I could see the possibility for a lot of problems here,” the judge said. “But I can see how in advance of trial [that] making public statements about potential witnesses is going to, in and of itself, affect the orderly administration of justice and could run afoul of his release conditions.”

She told Mr. Trump’s legal team, “Your client’s defense is supposed to happen in this courtroom, not on the internet. And to the extent your client wants to make statements on the internet, they always have to yield to witness security and witness safety.”

Prosecutors plan to turn over 11.6 million pages of documents initially to Mr. Trump’s legal team. Prosecutor Thomas Windom said other pre-trial material will be turned over in the coming weeks, with most of the documents to be delivered to the defense prior to Aug. 28.

The judge cautioned both sides to prevent a “carnival” atmosphere in the case before a trial takes place.

“The more a party makes inflammatory statements about this case … the greater the urgency will be that we proceed to trial quickly,” she said.

• This article is based in part on wire service reports.