President Trump has threatened to shut down Twitter, regulate social media and expand the government’s power to oversee the Web — all part of an assault against Silicon Valley tech giants that he has long accused of trying to undermine his reelection.

But what began this week as a verbal spat has since evolved into a simmering legal battle in the digital age, leading experts across the political spectrum to fear for the future of free expression on the Internet.

The tensions erupted again into public view Friday, after Twitter took the unprecedented step of limiting the reach and visibility of one of Trump’s tweets. The company said the president had glorified violence, in violation of its policies, by decrying protesters in Minneapolis as “THUGS” and saying that looting would lead to “shooting.”

Twitter hid Trump’s tweet from public view, appending a label to it that also prevented it from being easily shared — a punishment the company meted out a second time hours later when the White House sent the same comment from its official account. The move left Trump and his allies seething, promising to penalize Twitter and its social media peers over unproven claims about censorship.

“They have targeted Republicans, Conservatives & the President of the United States,” Trump charged in a tweet Friday morning.

The actions of Trump and his top allies in recent days have troubled free-speech advocates, current and former federal regulators and the very social media companies on which the president has come to rely. Trump had never targeted the tech industry in this way before, despite years of verbal lashings, so critics saw in Trump’s behavior a new attempt to use the Oval Office as a means to exact political revenge, with potentially costly consequences.

“It is one thing for political candidates to be making aggressive statements toward tech companies and the media,” said Adrian Shahbaz, the director of technology and democracy at Freedom House, a human rights watchdog that tracks press freedom. “It’s another thing for people in power to be making those same threats.”

Shahbaz fretted that Trump might be “using whatever means possible to coerce companies and manipulate speech for electoral gain,” adding, “The words of the president matter.”

The White House declined to comment. The Trump campaign pointed to previous comments accusing the industry of improperly setting itself up as the “arbiters of truth.”

The emerging standoff between Trump and the tech industry reflects years of tension dating to the days before he won the presidency, when many executives and engineers in the liberal-leaning San Francisco Bay area actively campaigned against him. The relationship between Silicon Valley and Washington never fully thawed, and Trump has continued to harbor an intense, public skepticism of some of the very social media sites that were widely seen as critical to his 2016 victory.

The president’s attacks hinge on allegations that Twitter and other tech companies suppress conservatives, systematically limiting their reach online. Such views are shared widely among Republicans, including on Capitol Hill, even as Internet giants insist on their political neutrality.

“The big tech billionaires are so drunk with power that they are now willing to try to censor and silence the president of the United States,” Sen. Ted Cruz (R-Tex.), who has held multiple hearings on the issue, said Friday. “Big tech’s claim there are no clear empirical data demonstrating bias is reminiscent of the child who kills his parents and then pleads mercy of the court because he’s an orphan.”

A YouGov poll in July similarly found widespread belief in claims of political bias, with nearly half of all Americans saying they were somewhat or very likely to be true. Among GOP voters, 3 out of 4 said they were somewhat or very likely to be correct.

The attacks have put tech companies, including Twitter, into a political vise, trapped amid competing obligations to police a wide array of abusive content on the Internet while at the same time satisfying politicians who question their motives and decisions — all in the midst of a high-stakes election year.

“The companies have become more willing to change the rules based on political pushback,” said Alex Stamos, a former Facebook chief security officer and now head of the Stanford Internet Observatory, which studies disinformation. “It’s been happening for years. It’s just that Trump has gone well beyond where others were willing to go.”

Trump long has threatened to penalize Silicon Valley over allegations of bias, even at one point holding a summit at the White House to explore claims of censorship. But he formalized his threats after Twitter took the rare step to label two of Trump’s tweets about the 2020 election and redirect users to fact-checking resources.

An executive order the president signed Thursday directed federal agencies to consider rethinking a critical portion of law, known as Section 230, that spares tech companies from being held liable for the content posted by their users. If federal agencies carry that out as Trump intends, probing and penalizing social media sites for their practices, the order could affect every app, website and digital service people use to congregate online.

“A small handful of powerful social media monopolies controls a vast portion of all public and private communication in the United States,” Trump said as he signed the directive.

The prospect for wide-ranging consequences imperiling free speech on the Web quickly united a rare crop of critics, including the American Civil Liberties Union, conservative groups funded by the Koch family, Democratic lawmakers and major technology companies. It raised significant legal questions, said Tom Wheeler, who was chairman of the Federal Communications Commission under President Barack Obama.

Its issuance alone amounted to a form of “cold coercion,” Wheeler said. “It is to create consequences for editorial decisions in which he doesn’t agree.”

Twitter for years had resisted such pressure to discipline the president for comments seen as toxic or false, believing users should have an unfettered view into their leaders’ thoughts. On Friday, the company adopted a more aggressive approach to another Trump tweet, focused on the unrest in Minneapolis. While Twitter decided to limit the reach of that tweet, Facebook, in contrast, did not take action against the president’s remarks. The company’s chief executive, Mark Zuckerberg, posted online that he had a “visceral negative reaction to this kind of divisive and inflammatory rhetoric” — but he said it did not break the social networking site’s rules.

“I know many people are upset that we’ve left the president’s posts up, but our position is that we should enable as much expression as possible unless it will cause imminent risk of specific harms or dangers spelled out in clear policies,” he said.

In blasting the tech companies, Trump exploited the vulnerabilities of an industry whose products and services remain widely popular. The industry’s legacy of missteps — including disinformation that spread virally online during the 2016 election and major privacy mishaps — have contributed to an erosion of its overall public support.

A Pew Research Center poll in July found that the percentage of Americans who view tech as having an overall positive impact had fallen sharply since 2015, down from 71 percent to 54 percent. Among Republicans, the number fell to 44 percent.

Daniel Kriess, an associate professor of journalism and media at the University of North Carolina at Chapel Hill, viewed Trump’s actions through the prism of the 2020 presidential race. “This is the president deliberately picking a fight with Silicon Valley tech companies because he stands to gain electorally,” he said. “Particularly for his base, this is a very easy foil for President Trump.”