China's president Xi Jinping has said there will be no tolerance for any acts seen as jeopardising stability and security.
The president employed some of his harshest language yet towarsd pro-democracy activities in the former British territory.
In his address during a swearing-in ceremony for Carlie Lam as Hong Kong's chief executive, Mr Xi pledged Beijing's support for the "one country, two systems" blueprint under which the territory was returned to Chinese rule in 1997.
But he said Hong Kong had to do more to shore up security and boost patriotic education, apparently referring to pieces of legislation long delayed by popular opposition.
And he warned that anyone threatening China or Hong Kong's political stability would be crossing a red line and their actions would be considered "absolutely impermissible" - words certain to concern those already wary of tightening restrictions on political life in the city.
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", he said.
Mr Xi's three-day visit aimed at stirring Chinese patriotism prompted a massive police presence.
Protesters fear Beijing's ruling Communist Party is increasing its control over Hong Kong's political and civil affairs, undermining a pledge to allow it to retain its own legal and other institutions for 50 years.
Ms Lam was sworn in as Hong Kong's new leader on the city's 20th anniversary of its handover from British to Chinese rule in a ceremony presided over by Mr Xi.
She and her cabinet swore to serve China and Hong Kong and to uphold the Basic Law, the territory's mini-constitution.
In a short speech, she reviewed the dynamic financial centre's achievements and challenges, pledged to support central government initiatives and declared that "the future is bright".
The career bureaucrat was selected through a process decried by critics as fundamentally undemocratic, involving just a sliver of a per cent of Hong Kong's three million-plus voters.
A little over a mile away, a small group of activists linked to the pro-democracy opposition clashed with police and counter-protesters.