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 harbor-front venue close to where the last colonial governor, Chris Patten, had tearfully handed back Hong Kong to Beijing at a rain-soaked ceremony two decades earlier.

"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 a 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, which led to the ceding of Hong Kong to the British.