On a muggy, late spring evening, Tuan Pham awoke to the police storming his house in Hanoi, Vietnam.
They marched him to a police station and made their demand: Hand over your Facebook password. Mr. Tuan, a computer engineer, had recently written a poem on the social network called “Mother’s Lullaby,” which criticized how the communist country was run.
One line read, “One century has passed, we are still poor and hungry, do you ask why?”
Mr. Tuan’s arrest came just weeks after Facebook offered a major olive branch to Vietnam’s government. Facebook’s head of global policy management, Monika Bickert, met with a top Vietnamese official in April and pledged to remove information from the social network that violated the country’s laws.
While Facebook said its policies in Vietnam have not changed, and it has a consistent process for governments to report illegal content, the Vietnamese government was specific. The social network, they have said, had agreed to help create a new communications channel with the government to prioritize Hanoi’s requests and remove what the regime considered inaccurate posts about senior leaders.
Populous, developing countries like Vietnam are where the company is looking to add its next billion customers — and to bolster its ad business. Facebook’s promise to Vietnam helped the social media giant placate a government that had called on local companies not to advertise on foreign sites like Facebook, and it remains a major marketing channel for businesses there.
The diplomatic game that unfolded in Vietnam has become increasingly common for Facebook. The internet is Balkanizing, and the world’s largest tech companies have had to dispatch envoys to, in effect, contain the damage such divisions pose to their ambitions.
The internet has long had a reputation of being an anything-goes place that only a few nations have tried to tame — China in particular. But in recent years, events as varied as the Arab Spring, elections in France and confusion in Indonesia over the religion of the country’s president have awakened governments to how they have lost some control over online speech, commerce and politics on their home turf.
Even in the United States, tech giants are facing heightened scrutiny from the government. Facebook recently cooperated with investigators for Robert S. Mueller III, the special counsel investigating Russian interference in the American presidential election. In recent weeks, politicians on the left and the right have also spoken out about the excess power of America’s largest tech companies.
As nations try to grab back power online, a clash is brewing between governments and companies. Some of the biggest companies in the world — Google, Apple, Facebook, Amazon and Alibaba among them — are finding they need to play by an entirely new set of rules on the once-anarchic internet.
And it’s not just one new set of rules. According to a review by The New York Times, more than 50 countries have passed laws over the last five years to gain greater control over how their people use the web.
“Ultimately, it’s a grand power struggle,” said David Reed, an early pioneer of the internet and a former professor at the M.I.T. Media Lab. “Governments started waking up as soon as a significant part of their powers of communication of any sort started being invaded by companies.”
Facebook encapsulates the reasons for the internet’s fragmentation — and increasingly, its consequences.
The company has become so far-reaching that more than two billion people — about a quarter of the world’s population — now use Facebook each month. Internet users (excluding China) spend one in five minutes online within the Facebook universe, according to comScore, a research firm. And Mark Zuckerberg, Facebook’s chief executive, wants that dominance to grow.
But politicians have struck back. China, which blocked Facebook in 2009, has resisted Mr. Zuckerberg’s efforts to get the social network back into the country. In Europe, officials have repudiated Facebook’s attempts to gather data from its messaging apps and third-party websites.
The Silicon Valley giant’s tussle with the fracturing internet is poised to escalate. Facebook has now reached almost everyone who already has some form of internet access, excluding China. Capturing those last users — including in Asian nations like Vietnam and African countries like Kenya — may involve more government roadblocks.
“We understand that and accept that our ideals are not everyone’s,” said Elliot Schrage, Facebook’s vice president of communications and public policy. “But when you look at the data and truly listen to the people around the world who rely on our service, it’s clear that we do a much better job of bringing people together than polarizing them.”
Mr. Zuckerberg had wined and dined Chinese politicians, publicly showed off his newly acquired Chinese-language skills — a moment that set the internet abuzz — and talked with a potential Chinese partner about pushing the social network into the market, according to a person familiar with the talks who declined to be named because the discussions were confidential.
At a White House dinner in 2015, Mr. Zuckerberg had even asked the Chinese president, Xi Jinping, whether Mr. Xi might offer a Chinese name for his soon-to-be-born first child — usually a privilege reserved for older relatives, or sometimes a fortune teller. Mr. Xi declined, according to a person briefed on the matter.
But all those efforts flopped, foiling Facebook’s attempts to crack one of the most isolated pockets of the internet.