Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

HONG KONG — Chinese President Xi Jinping on Saturday said any activities in Hong Kong seen as threatening China's sovereignty and stability would be "absolutely impermissible," employing some of his harshest language yet toward pro-democracy activities in the territory.

In a speech on Saturday marking 20 years since the city became a semi-autonomous Chinese region after its handover from Britain, Xi pledged Beijing's support for the "one country, two systems" blueprint, under which Hong Kong controls many of its own affairs and retains civil liberties including free speech.

However, he said Hong Kong had to do more to shore up security and boost patriotic education, in a veiled reference to legislation long-delayed by popular opposition.

Pro-democracy activists try to push past a security barricade to deliver their demands to President Xi Jinping in Hong Kong on Friday. Ng Han Guan / AP

And he appeared to put on notice a new wave of activists pushing for more autonomy or even independence, saying challenges to the power of China's central government and Hong Kong's leaders wouldn't be tolerated.

Any attempt to challenge China's sovereignty, security and government authority 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.

Hong Kong has been roiled by political turmoil in recent years that brought tens of thousands of protesters onto the streets in 2014 demanding democratic reforms. Those calls were ignored by Beijing and Xi indicated there would be no giving ground in the future.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Related: China Calls on U.S. to Halt $1.4 Billion Arms Sale to Taiwan

"Making everything political or deliberately creating differences and provoking confrontations will not resolve the problems," he said. Hong Kong "cannot afford to be torn apart by reckless moves or internal rifts."

Related: Beijing's Pick Lam Chosen as Hong Kong Leader, in No Surprise

While former colonial master Britain and other Western democracies have expressed concerns about Beijing's actions in Hong Kong, China has increasingly made clear it brooks no outside criticism or attempts at intervention.

Xi said China had made it "categorically clear" in talks with Britain in the 1980s that "sovereignty is not for negotiation."

"Now that Hong Kong has returned to China, it is all the more important for us to firmly uphold China's sovereignty, security and development interests," he said.

Earlier, Xi presided over a swearing-in ceremony for Carlie Lam, Hong Kong's fifth chief executive since 1997. The life-long bureaucrat and her Cabinet swore to serve China and Hong Kong and to uphold the Basic Law, the territory's mini-constitution.

In a speech that ran far shorter than Xi's 32-minute address, Lam reviewed the dynamic financial center's achievements and challenges, pledged to support central government initiatives and declared that "the future is bright."

Lam prevailed over a much more popular rival in an election decried by many as fundamentally undemocratic, with only a sliver of a percent of Hong Kong's more than 3 million registered voters taking part.

President Xi Jinping, center, sings with Hong Kong Chief Executive Leung Chun-ying, left, Chief Executive-elect Carrie Lam, right, at a ceremony marking the 20th anniversary of Hong Kong's handover to China. Kin Cheung / AP

Xi was due to return to Beijing midday Saturday. His three-day visit aimed at stirring Chinese patriotism had prompted a massive police presence and also included a visit to the People's Liberation Army garrison, which usually maintains a low profile in the territory.

Ahead of a flag raising ceremony Sunday, a small group of activists linked to the pro-democracy opposition sought to march on the venue carrying a replica coffin symbolizing the death of the territory's civil liberties. They were swiftly stopped by police and Chinese flag-waving counter protesters, with the action ending about an hour later.

Xi's remarks will likely fuel fears among critics that Beijing's ruling Communist Party is tightening its grip over the city's political and civil affairs following a string of recent incidents.

Those include the abductions of five Hong Kong booksellers to the mainland starting in late 2015 for selling gossipy titles about elite Chinese politics to Chinese readers. One of the men, Gui Minhai, is still being held.