Crowds spilling out into the streets chanted “resist till the end” and “Hong Kong independence”.
Police fired water cannon to chase them away and said they had made more than 300 arrests for illegal assembly and other offences, with nine involving suspected violations of the new law.
Earlier, police cited the law for the first time in confronting protesters.
“You are displaying flags or banners/chanting slogans/or conducting yourselves with an intent such as secession or subversion, which may constitute offences under the … national security law,” police said in a message displayed on a purple banner.
The law will punish crimes of secession, subversion, terrorism and collusion with foreign forces with up to life in prison and officially set up mainland security agencies in Hong Kong for the first time, with powers beyond city laws.
China’s parliament adopted it in response to months of pro-democracy protests last year triggered by fears that Beijing was stifling the city’s freedoms, guaranteed by a “one country, two systems” formula agreed when it returned to Chinese rule.
Authorities in Beijing and Hong Kong have repeatedly said the legislation is aimed at a few “troublemakers” and will not affect rights and freedoms, nor investor interests.
But critics fear it will crush the freedoms that are seen as key to Hong Kong’s success as a financial centre.
“With the release of the full detail of the law, it should be clear to those in any doubt that this is not the Hong Kong they grew up in,” said Hasnain Malik, head of equity research, Tellimer in Dubai.
“The difference is that US and China relations are far worse and this could be used as a pretext to impede the role of Hong Kong as a finance hub.”
The United States and its Asian and Western allies have criticised the legislation. Britain said it would stand by its word and offer all those in Hong Kong with British National Overseas status a “bespoke” immigration route. Britain and Canada also updated their travel advice for Hong Kong, saying there was an increased risk of detention.
British Foreign Secretary Dominic Raab described Wednesday’s protests as heartbreaking and reprimanded HSBC and other banks for supporting the new law, saying the rights of Hong Kong should not be sacrificed for bankers’ bonuses.
In Beijing, Zhang Xiaoming, executive deputy director of Beijing’s Hong Kong and Macau Affairs Office, told reporters suspects arrested by a new Beijing-run security office could be tried on the mainland.
He said the new office abided by Chinese law and that Hong Kong’s legal system could not be expected to implement the laws of the mainland. Article 55 of the law states that Beijing’s security office in Hong Kong could exercise jurisdiction over “complex” or “serious” cases.
“The law is a birthday gift to [Hong Kong] and will show its precious value in the future,” Zhang said, adding the law would not be applied retroactively.
On July 1 last year, hundreds of protesters stormed and vandalised the city’s legislature to protest against a now-scrapped bill that would have allowed extraditions to mainland China.
Those protests evolved into calls for greater democracy, paralysing parts of the city and paving the way for Beijing’s imposition of the law this week.
Speaking at a flag-raising ceremony to mark the handover anniversary, the city’s Beijing-backed leader, Carrie Lam, said the law was the most important development since the city’s return to Chinese rule.
“It is also an inevitable and prompt decision to restore stability,” Lam said at the harbour-front venue where 23 years ago the last colonial governor, Chris Patten, a staunch critic of the security law, tearfully handed back Hong Kong to China.
Some pro-Beijing officials and political commentators say the law was aimed at sealing Hong Kong’s “second return” to the motherland after the first failed to bring residents to heel.
Luo Huining, the head of Beijing’s top representative office in Hong Kong, said at the ceremony the law was a “common aspiration” of Hong Kong citizens.
Critics denounced the lack of transparency on details of the legislation until it was unveiled. It came into force at 11pm local time on Tuesday (1am AEST).
Some pro-democracy activists gave up membership of their groups just before the law came into force, though calling for the campaign for democracy to go on offshore.
“I saw this morning there are celebrations for Hong Kong’s handover, but to me it is a funeral, a funeral for ‘one country two systems’,” said pro-democracy lawmaker Kwok Ka-ki.