By blocking users on Twitter, President Trump has violated the First Amendment, a federal judge ruled on Wednesday.

The lawsuit was brought by seven Twitter users — including a Texas police officer, a New York comedy writer and a Nashville surgeon — who claimed that Mr. Trump’s Twitter feed was an official government account and that preventing users from following it was unconstitutional.

In her ruling, Judge Naomi Reice Buchwald wrote that the plaintiffs who sought to view and engage with Mr. Trump’s tweets alongside those who were not restricted were “protected by the First Amendment.” The judge, though, did not require the president or Twitter to unblock anyone.

The number of users blocked from the president’s account @realDonaldTrump, which has more than 52 million followers, is known only to Mr. Trump, to those who have access to his account and to Twitter.