Activists and dissenters are routinely harassed, jailed or tied up in legal cases in Vietnam, a one-party state which is hyper-sensitive to critical public opinion.
Social media and Internet forums have provided a rare platform to share and debate views against authorities.
But the bill waved through by an overwhelming majority of MPs in the National Assembly, is poised to end that relative freedom.
Bitcoin slides as South Korean exchange hit by hackers
The law's far-reaching provisions mean internet companies will have to remove posts deemed to be a "national security" threat within a day and store personal information and data of their users inside Vietnam.
"Currently, Google and Facebook store personal data of Vietnamese users in Hong Kong and Singapore," Vo Trong Viet, chairman of National Assembly's defense and security committee told lawmakers.
"Putting data centres in Vietnam will increase expenses for the service providers... but it is necessary to meet the requirements of the country's cybersecurity."
The new law also outlaws material encouraging public gatherings or that "offends" everything from the national flag to the country's leaders and "heroes".
There was no immediate detail of the punishment for breaching the law.
Only 15 out of the 466 MPs present in the rubber-stamp assembly voted against the bill, which the government says will become law from January 1, 2019.
Rights advocates said the bill further shrinks the small space for debate.
"In the country's deeply repressive climate, the online space was a relative refuge where people could go to share ideas and opinions with less fear of censure by the authorities," said Clare Algar of Amnesty International.
Iran hit by global cyber attack that left US flag on screens
"With the sweeping powers it grants the government to monitor online activity, this vote means there is now no safe place left."
The country's conservative leadership, which has been in charge since 2016, is waging a crackdown on activists and dissidents.
It has jailed scores of bloggers and dissidents for criticising the regime.
At least 26 dissidents and actives have been prosecuted during the first five months this year, according to Human Rights Watch.
The government has also unveiled a 10,000-strong brigade to fight cybercrimes and "wrongful views" on the internet, according to state media reports.
The unit, dubbed Force 47, is also tasked with fighting anti-state propaganda on the web.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ