Chinese President Xi Jinping swore in Hong Kong's new leader on Saturday with a stark warning that Beijing will not tolerate any challenge to its authority in the divided city as it marked the 20th anniversary of its return from Britain to China.

A massive deployment of police blocked roads and prevented protesters from getting to the harbour-front venue close to where two decades earlier, the last colonial governor, Chris Patten, tearfully handed back Hong Kong to Beijing at a rain-soaked ceremony.

"Any attempt to endanger China's sovereignty and security, challenge the power of the central government ... or use Hong Kong to carry out infiltration and sabotage activities against the mainland is an act that crosses the red line and is absolutely impermissible," Xi said in a sweeping speech that touched upon the "humiliation and sorrow" China suffered during the first Opium War in the early 1840s that led to the ceding of Hong Kong to the British.

Hong Kong has been racked by demands for full democracy and, more recently, by calls by some pockets of protesters for independence, a subject that is anathema to Beijing.

Xi's words were his strongest yet to the city at a time of heightened social and political tensions and concerns over what some in Hong Kong perceive as increased meddling by Beijing in the city's affairs.

"It's a more frank and pointed way of dealing with the problems (in Hong Kong)," said former senior Hong Kong government adviser Lau Siu-kai on Hong Kong's Cable Television.

"The central government's power hasn't been sufficiently respected... they’re concerned about this."

Under Hong Kong's mini-constitution, the Basic Law, the financial hub is guaranteed wide-ranging autonomy and freedoms for "at least 50 years" after 1997 under a "one country, two systems" formula praised by Xi.

But Beijing's refusal to grant universal suffrage to Hong Kong triggered nearly three months of street protests in 2014 that at times erupted into violent clashes and posed one of the greatest populist challenges to the central government in decades.

Xi, dressed in a dark suit and striped red tie, was addressing a packed hall of dignitaries and mostly pro-Beijing establishment figures, speaking for more than 30 minutes, after swearing in Hong Kong's first female leader, Carrie Lam.

"I will, as I always have ... firmly take actions in accordance with the law against any acts that will undermine the country's sovereignty, security and development interests," Lam said after she was sworn in along with her cabinet.

NATIONAL SECURITY

Xi hinted that the central government was in favour of Hong Kong introducing "national security" legislation, a controversial issue that brought nearly half a million people to the streets in protest in 2003 and ultimately forced former leader Tung Chee-hwa to step down.

"Hong Kong needs to improve its systems to uphold national sovereignty, security and development interests. It needs to enhance education and raise public awareness of history and culture of the Chinese nation," he said.

A small group of pro-democracy activists near the venue were roughed up by a group of men who smashed up some props in ugly scuffles while surrounded by more than 100 police. Nine democracy protesters, including Joshua Wong and lawmaker "long hair" Leung Kwok-hung, were bundled into police vans while several pro-China groups remained, cheering loudly and waving red China flags.

The activists, in a later statement, said the assailants had been "pro-Beijing triad members".

Other protesters unfurled a massive yellow banner, with the words "I want real universal suffrage", on the waterfront of Hong Kong's Victoria Harbour, but were later taken away by police.

Beijing-backed civil servant Lam was chosen to be Hong Kong's next leader in March by a 1,200-person "election committee" stacked with pro-China and pro-establishment loyalists.

[For a link to Reuters handover stories, http://reut.rs/2sje26J]

Lam, speaking in Mandarin instead of the Cantonese dialect widely used in Hong Kong and elsewhere in southern China, said she wanted to create a harmonious society and explore new land supply in a city where the sky-high cost of housing has also triggered discontent.

Xi acknowledged housing was a significant issue for the new government.

"Hong Kong's traditional strengths start to lose the edge while new drivers of growth are yet to emerge. Housing and other issues that affect the daily life of the people have become more serious," he said.

Upwards of 100,000 thousand protesters are expected to hit the streets for an annual march in the afternoon whose theme is to "retake Hong Kong for a real and fully fledged democracy".