A federal judge in San Francisco on Friday dismissed former President Donald J. Trump’s lawsuit against Twitter over the social media company’s decision to bar him from its platform permanently after the Jan. 6 attack at the U.S. Capitol.

The judge, James Donato of the United States District Court for the Northern District of California, wrote that he was not persuaded that Twitter had infringed on Mr. Trump’s free speech rights when it shut down his account on Jan. 8, 2021, two days after a mob spurred by Mr. Trump’s “stop the steal” lies stormed the Capitol in hopes of overturning the presidential election results.

At the time, the tech giant said that Mr. Trump had violated its rules against glorifying violence with a pair of tweets, including one praising his supporters as “patriots.” The decision stripped Mr. Trump of his favorite megaphone: He had used Twitter to lob insults and grievances and had amassed more than 88 million followers.

In his lawsuit against Twitter, Mr. Trump had asserted that the San Francisco-based company had been pandering to liberal Democrats by barring him from its platform and had sought to silence contradictory viewpoints.

In mounting a First Amendment claim, Mr. Trump had argued that Twitter was effectively functioning like the government. But Judge Donato was unpersuaded, saying that Mr. Trump’s claim that Twitter had behaved like a state actor was unsubstantiated.

“The amended complaint merely offers a grab-bag of allegations to the effect that some Democratic members of Congress wanted Mr. Trump, and ‘the views he espoused,’ to be banned from Twitter because such ‘content and views’ were “contrary to those legislators’ preferred points of view,” Judge Donato wrote.

A Twitter spokesman declined to comment about the ruling. A spokeswoman for Mr. Trump did not immediately respond to a request for comment.

Five people whose Twitter accounts were permanently suspended had joined Mr. Trump as plaintiffs in the lawsuit, along with the American Conservative Union. They argued that the bans amounted to censorship.

The ruling came a little more than a week after Elon Musk, the world’s richest man, struck a deal to buy Twitter for about $44 billion.

The acquisition by Mr. Musk, the chief executive of Tesla and founder of SpaceX, prompted speculation about whether Mr. Musk would seek to change the platform’s guidelines for posting and potentially clear a path for Mr. Trump to return. Some Republicans have expressed quiet reservations about a possible Trump return, worrying that he could distract from the party’s messaging ahead of the midterm elections.

While many Republicans cheered Mr. Musk’s planned takeover of the tech giant, Mr. Trump told Fox News last month that he would stick with posting on his own social network, Truth Social, a fledgling platform that has endured early struggles. “I am not going on Twitter,” he said, but he added that he hoped “Elon buys Twitter, because he’ll make improvements to it.”