HONG KONG — Twitter users here deleted their accounts en masse. Political parties disbanded, including the one founded by democracy activist Joshua Wong. Restaurants and cafes removed posters showing their support for the movement.

Even before Hong Kong residents had full details on Beijing’s new national security law Tuesday, a chilling effect was underway — silencing residents who have fought to preserve the territory’s autonomy and political freedoms.

When the details of the law were published shortly before midnight in Hong Kong, they were more draconian than many predicted. The law effectively ends the long-cherished freedom of speech that Hong Kong residents have had, putting them under the same threat of life imprisonment if they criticize Beijing’s government, as other Chinese nationals face. It also gives the government wide berth to crack down on organizations with foreign funding or ties.

China adopted the measures Tuesday despite Western objections and annexed the new codes to Hong Kong’s mini-constitution. The details called for a maximum life sentences for those found to be guilty of four broadly defined crimes of “separatism,” “subversion,” “terrorism” and “collusion with foreign forces.”

Punishments would be lowered for citizens who provided incriminating information about others, legislation noted.

The legislation will establish a new national security council in Hong Kong led by officials handpicked by Beijing. It also creates law enforcement agencies staffed with Chinese officials and a new magistrate court in Hong Kong that will specialize in national security cases and potentially try defendants without a jury if the cases involved state secrets.

In some instances, Chinese prosecutors and investigators will step in to directly handle cases.

The law will also greatly expand police powers to seize electronic equipment and “intercept communications and covertly surveil people reasonably suspected of crimes against national security.”

In a news conference on Wednesday, government officials in Beijing sought to portray the law as a by-the-books legislative process, not a reneging on Beijing’s “one country, two systems” commitments.

“It strictly followed our country’s legislative process,” said Shen Chunyao, director of legislative affairs commission for the National People’s Congress standing committee. He said that due to sensitivities around the law, officials decided not to open up the draft to public comment in advance, but sought input from Hong Kong local officials out of the public eye.

In Hong Kong, the effect of the law’s passage was swift. Wong, the young democracy activist who rose to prominence while still a student during the 2014 street protests calling for universal suffrage, announced Tuesday that he would end his association with Demosisto, the party he co-founded. Co-founders Nathan Law and Agnes Chow followed, and by the afternoon, the entire party had disbanded.

Wong said he hopes the “international community will continue to speak up for Hong Kong” and defend its “last bit of freedom.”

Other groups that support Hong Kong independence — a once-fringe idea that has gained traction at street protests, and a red line for Beijing — said they would cease operations in the city and move abroad.

“It is a complete change of the environment, not only for journalists, [nongovernment organizations] and scholars, but ultimately it will affect everybody in Hong Kong, including business,” said Ho-fung Hung, a political economist at Johns Hopkins University.

Chinese leader Xi Jinping signed the law Tuesday, and it took effect Wednesday.

“Beijing will not change its course of action to end chaos and violence in Hong Kong, to protect national security and to preserve the country’s sacred territorial integrity and sovereign rights simply because of U.S. pressure,” the state-run Xinhua News Agency warned in a commentary.

The United States has responded by restricting visas for Chinese officials and suspending trade privileges under which Washington has treated Hong Kong separately from mainland China.

Beijing’s liaison office in Hong Kong, briefing local delegates to China’s legislative body Tuesday, boasted that the measures were working.

“A comment was made today [by the speakers] that the law basically already has had its deterrent effect,” said Michael Tien, a pro-Beijing lawmaker who attended the meeting with the liaison office. “In the past, Hong Kong has been too free.”

Pro-democracy leaders characterized the law’s passage as akin to a second handover for Hong Kong, but one even more crushing.

“When I walked on the streets on midnight of June 30, the night of the handover, I felt sad, but we still had some hope that the mainland government may honor [its promise],” said Wu Chi-wai, who chairs the opposition Democratic Party. “We could also hope on the possibility of having genuine universal suffrage.”

Now, he added, “we are not only denied the hope of a democratic political system, we also will no longer have our freedoms of press, speech, expression, protests — all of that will be over.”

Tien and others who attended the liaison office meeting said full details of the law were not provided. Representatives, Tien said, were told that the law would not be retroactive and that most national security cases would be heard by a jury or at least three judges. In some severe cases, he added, Beijing will “have the right to exercise jurisdiction” — effectively extraditing someone from Hong Kong to mainland China — and in those cases, the maximum penalty would be life in prison rather than the death penalty.

“The intention is not for it to suffocate everyone,” Tien added.

Stanley Ng, a deputy to the National People’s Congress in China, said in a video statement that China has kept the law deliberately vague to deliver the “real effects of intimidation and deterrence.”

“You can see the rebels in Hong Kong are now in turmoil,” he added.

Under the terms of Hong Kong’s 1997 handover from Britain to China, the territory is meant to control its internal affairs through its own political structure. The process in which the security law was passed — entirely controlled by Beijing, without input from Hong Kong’s leaders and without their knowledge of its content — is unprecedented in the city’s 23 years under Chinese rule.

Changhao Wei, founder and editor of the National People’s Congress Observer blog, said the Hong Kong legislation was the first time since 2012 that China passed a new law without first releasing a draft for public consultation.

Asked Tuesday about the law, Hong Kong Chief Executive Carrie Lam told reporters it would not be appropriate for her to comment. Later, in a recorded address to the United Nations Human Rights Council, she said that the legislation was “urgently needed,” echoing reassurances from the liaison office that it would not be retroactive.

Hong Kong would exercise jurisdiction for offenses under the law except in “rare, specified situations,” she added.

“The law will not affect Hong Kong’s renowned judicial independence. It will not affect legitimate rights and freedoms of individuals,” Lam said.

The anniversary of the 1997 handover is Wednesday, July 1. On that date last year, anti-
government protesters pushing back against a bill that would have allowed extraditions to mainland China broke into Hong Kong’s legislative council complex, occupied the chamber and covered over references to the “People’s Republic of China.”

Pro-democracy groups have continued to call for protests July 1, which for years have been routine. Wu and Figo Chan, a leader of the Civil Human Rights Front, the group that organized peaceful marches last year, said they would press ahead with a march Wednesday in their capacity as private citizens.

“We all understand the price we have to pay is heavier than before, but we have to do it,” Wu said.

Observers, noting a change in police tactics, the new security law and a climate of fear in Hong Kong, say it will be difficult to get a similar demonstration off the ground. “Everyone is going to adjust in order not to fall under the purview of the law,” said Jean-Pierre Cabestan, a professor of political science at Hong Kong Baptist University. “People are likely to stop openly challenging the Communist Party.”

“But Hong Kong people,” he added, “won’t abandon their ideals. They believe in a liberal democracy, and they believe in liberal values.”

Tiffany Liang, Timothy McLaughlin and Gerry Shih contributed to this report.