The federal prosecutors who charged former President Donald J. Trump this month with conspiring to overturn the 2020 election got access this winter to a trove of so-called direct messages that Mr. Trump sent others privately through his Twitter account, according to court papers unsealed on Tuesday.

While it remained unclear what sorts of information the messages contained and who exactly may have written them, it was a revelation that there were private messages associated with the Twitter account of Mr. Trump, who has famously been cautious about using written forms of communications in his dealings with aides and allies.

The court papers disclosing that prosecutors in the office of the special counsel, Jack Smith, obtained direct messages from Mr. Trump’s Twitter account emerged from a fight with Twitter over the legality of executing a warrant on the former president’s social media. Days after the attack on the Capitol on Jan. 6, 2021, the platform shut down his account.

The papers included transcripts of hearings in Federal District Court in Washington in February during which Judge Beryl A. Howell asserted that Mr. Smith’s office had sought Mr. Trump’s direct messages — or DMs — from Twitter as part of a search warrant it executed on the account in January.

In one of the transcripts, a lawyer for Twitter, answering questions from Judge Howell, confirmed that the company had turned over to the special counsel’s office “all direct messages, the DMs” from Mr. Trump’s Twitter account, including those sent, received and “stored in draft form.”

The lawyer for Twitter told Judge Howell that the company had found both “deleted” and “nondeleted” direct messages associated with Mr. Trump’s account.

The warrant was first revealed last week when a federal appeals court in Washington released court papers about Twitter’s attempt to challenge certain aspects of the warrant.

The court papers unsealed on Tuesday revealed that Mr. Smith’s prosecutors sought “all content, records and other information” related to Mr. Trump’s Twitter account from October 2020 to January 2021, including all tweets “created, drafted, favorited/liked or retweeted” by the account and all direct messages sent from, received by or stored in draft form by the account.

The warrant, which was signed by a federal judge in Washington in January after Elon Musk took over Twitter, now called X, is the first known example of prosecutors directly searching Mr. Trump’s communications and adds a new dimension to the scope of the special counsel’s efforts to investigate the former president.

Mr. Trump’s Twitter account was often managed by Dan Scavino, a longtime adviser going back to his days in his private business, and it was unclear if any direct messages were from when he was using the account.

CNN earlier reported the revelation that Mr. Trump’s direct messages were sought by the search warrant.

A spokesman for Mr. Trump, asked for comment, referred to a post the former president made on his social media website, Truth Social, on Monday, in which he called Mr. Smith a “lowlife” and accused him breaking into his Twitter account. “What could he possibly find out that is not already known,” Mr. Trump wrote.

The election charges filed against Mr. Trump accuse him of three overlapping conspiracies: to defraud the United States, to disrupt the certification of the election at a proceeding at the Capitol on Jan. 6 and to deprive people of the right to have their votes counted.

Mr. Trump’s relentless use of Twitter is detailed several times in the indictment.

The indictment notes, for instance, how Mr. Trump used Twitter on Dec. 19, 2020, to summon his followers to Washington on Jan. 6 for what he described as a “wild” protest. The message ultimately served as a lightning rod for both far-right extremists and ordinary Trump supporters who descended on the city that day, answering Mr. Trump’s call.

The indictment also describes how Mr. Trump used Twitter in the run-up to Jan. 6 to instill in his followers “the false expectation” that Vice President Mike Pence had the authority to use his role in overseeing the certification proceeding at the Capitol “to reverse the election outcome” in Mr. Trump’s favor.

On Jan. 6, Mr. Trump continued posting messages on Twitter that kept up this drumbeat of “knowingly false statements aimed at pressuring the vice president,” the indictment said. Ultimately, when Mr. Pence declined to give in, Mr. Trump posted yet another tweet blaming the vice president for not having “the courage to do what should have been done to protect our country and our Constitution.”

One minute after the tweet was posted, the indictment said, Secret Service agents were forced to evacuate Mr. Pence to a secure location. And throughout that afternoon, it added, rioters roamed the Capitol and its grounds, shouting chants like “Traitor Pence” and “Hang Mike Pence.”

When the special counsel’s office obtained the warrant for Mr. Trump’s Twitter account, prosecutors also got permission from a judge to force Twitter not to inform the former president that they were scrutinizing his communications.

If Mr. Trump had learned about the warrant, the court papers unsealed on Tuesday said, it “would result in destruction of or tampering with evidence, intimidation of potential witnesses or serious jeopardy to this investigation.”

Twitter challenged this so-called nondisclosure order, arguing that prosecutors had violated the company’s First Amendment rights by seeking to keep officials from communicating with Mr. Trump, one of its customers.

The company also asked to delay complying with the warrant until the issues surrounding the provision were resolved. Otherwise, it claimed, Mr. Trump would not have a chance to assert executive privilege in a bid to “shield communications made using his Twitter account.”

Ultimately, Twitter not only lost the fight but also was found to be in contempt of court for delaying complying with the warrant. Judge Howell fined the company $350,000.