Chinese President Xi Jinping has warned against “impermissible” challenges to Beijing’s authority over Hong Kong.
Mr Xi was speaking at the swearing-in of the territory’s new leader Carrie Lam, as it marks 20 years since its handover to China from Britain.
He took part in a series of lavish events, including a flag-raising ceremony, amid tight police security.
But clashes took place between pro-democracy and pro-Beijing demonstrators close to the site. Several were held.
The visit was Mr Xi’s first to the city since becoming the leader in 2013.
The visit also comes three years after mass pro-democracy rallies crippled parts of the territory for months.
He oversaw the swearing in of Ms Lam, the newly-elected chief executive of the territory, along with the rest of her cabinet.
She is Hong Kong’s first female leader.
In a speech, he said that Hong Kong needed to “improve its systems to uphold national sovereignty, security and development interests”.
“Any attempt to endanger China’s sovereignty and security, challenge the power of the central government.
Xi also said the use of Hong Kong to carry out infiltration and sabotage activities against the mainland is an act that crosses the red line and is absolutely impermissible.