Twitter’s decision this week to label President Trump’s tweets for the first time appeared to the world as a quick-response salvo in an escalating battle between Silicon Valley and Washington. But the tiny labels were actually two years in the making as the company grappled with a double standard for politicians.

That resulted in a fact-check label on misleading tweets about mail-in ballots, and then, on Friday, a label on a tweet about the Minnesota protests explaining that the tweet violated the company’s rules. It was the culmination of a series of quiet and incremental processes intended to dismantle a long-standing exception that the social media industry has made for the speech of politicians, say two Twitter employees, who spoke on the condition of anonymity out of concern that they could be targeted by opponents of the new policies.

Meanwhile, Facebook CEO Mark Zuckerberg defended the company’s decision to leave the president’s posts up on its site late Friday.

Twitter’s actions have subsequently become a flash point for a polarized country and could open the floodgates for unprecedented regulation of the tech industry.

Like many changes in Silicon Valley, Twitter’s reconsideration of its practices has its roots in the aftermath of the 2016 election, when social media companies were taken to task by Congress and the public for allowing rampant abuse of their platforms by Russian operatives and purveyors of false stories.

Long before Trump’s use of the platform for controversial statements, Twitter users, and particularly women and people of color, had also complained about the company doing nothing when they complained of harassment and abuse.

In late 2017, a month after congressional hearings on social media and Russian interference, a period of soul-searching began across social media companies. The following year, Facebook launched a major fact-checking effort and hired tens of thousands of content moderators to police its service. Twitter began purging large numbers of fake accounts, banned “dehumanizing speech” against certain categories of users, and embarked on a broad effort to solicit public comment about its speech policies.

But as the companies became more aggressive in policing their services and setting rules, they continued to exempt politicians, arguing that their comments were too “newsworthy” to censor.

Among the thousands of responses Twitter received, one of the most common was that the public felt Twitter — a company whose founders believed in a completely hands-off approach to free speech — should not have two categories of rules, one for politicians and one for everyone else.

At the same time, public events also began to shape Twitter’s thinking. World leaders, such as President Trump in the United States and Prime Minister Narendra Modi in India, used the platform as a preferred communication channel, and their comments ran up against the company’s new willingness to punish tweets that were dehumanizing, bullying, or causing real-world harm, one of the people said.

Twitter executives also watched in 2018 as Facebook struggled to respond to criticism that military leaders and government officials used violent social media posts to incite a genocide in Myanmar. The events in Myanmar solidified a growing feeling that exceptions should not be made for leaders, the person said.

The problem, however, was that, unlike Facebook, which has invested millions in a fact-checking effort, Twitter didn’t have any fact-checking at all. The company only had two black-and-white modes to deal with content: leave it up or take it down. In 2019, policy teams sought to clarify how the company would find a middle ground between those two poles.

The executives decided on labels. In 2019, The Washington Post first reported that Twitter planned to label content by world leaders or public officials that broke its policies. Twitter would still leave that content up because it was newsworthy. But they would attach a label to it.

Once executives on the company’s Trust and Safety team decided on labels as a strategy, they tasked the technologies team with building the code into Twitter’s service, which took another several months, one of the people said.

Last fall, the company used the labels a few times for comments by politicians outside the United States. Then it said it would apply fact-checking labels to manipulated media and did so for a manipulated video Trump retweeted about former vice president Joe Biden. Then the company said this month that it would apply fact-check labels to misinformation about the coronavirus.

This week, Twitter slapped a label on Trump himself for the first time. The label directed people to articles from news organizations including The Hill and The Washington Post that addressed Trump’s unsubstantiated claims that mail-in ballots are fraudulent.

Trump quickly directed his ire over the labels toward Twitter and took aim at social media companies as a whole. The president and his supporters singled out a Twitter executive for the decision, opening him up to online harassment. Trump once again accused social media companies of trying to “silence” conservative voices, a claim that Trump and some Republican members of Congress have raised over the past year. The companies have denied that claim.

Trump signed an executive order Thursday night that encouraged the Federal Communications Commission to rethink the scope of Section 230, a law that largely shields social media companies from liability over what users post on their sites. The order is Trump’s latest attempt to punish social media companies for what he claims is political bias against conservatives.

Trump further lashed out at Twitter on Friday when the company again labeled one of Trump’s tweets — this time limiting the public’s ability to view and share the tweet. Twitter’s label said the tweet, and another with the same message from the White House account, violated the company’s policies about glorifying violence.

“Section 230 should be revoked by Congress. Until then, it will be regulated!” the president tweeted shortly after Twitter labeled his tweet.

Facebook also waded into the growing controversy over social media’s role in fact-checking this week, when Zuckerberg said in an interview with Fox News that he doesn’t think digital platforms should act as the “arbiter of truth of everything that people say online.”

Zuckerberg posted a lengthy explanation Friday of why the company decided to leave Trump’s statements about Minneapolis untouched.

“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 wrote.

Twitter CEO Jack Dorsey responded to Zuckerberg’s Fox News interview on Wednesday, saying that labeling tweets does not make Twitter an “arbiter of truth.”

“We’ll continue to point out incorrect or disputed information about elections globally,” he tweeted. “And we will admit to and own any mistakes we make.”