Chinese president Xi Jinping has warned against ‘impermissible’ challenges to Beijing's authority over Hong Kong.
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 Xi's first to the city since becoming leader in 2013 and comes three years after mass pro-democracy rallies crippled parts of the territory for months.
He oversaw the swearing in of 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... 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.
He added that Hong Kong now enjoyed more freedom than ever before.
But while Hong Kong's Basic Law guarantees wide-ranging freedoms under the ‘one country, two systems’ formula, Beijing's refusal to grant universal suffrage has triggered sometimes violent unrest.
In Saturday's protests, pro-democracy party Demosisto said police had arrested five of its members, and four members from the League of Social Democrats.
Among those said by the group to have been arrested was Joshua Wong, the leader of the so-called umbrella protest movement.
In the ceremony the flags of China and Hong Kong were raised alongside one another to mark the 20-year anniversary of the city's handover of British rule.
Helicopters flew overhead as onlookers cheered at the ceremony in Golden Bauhinia Square, central Hong Kong.
On Friday, an official protest zone near the convention centre where Xi was guest of honour at an anniversary banquet and variety performance was heavily patrolled, as demonstrators gathered chanting ‘end one-party dictatorship’.
There is growing concern that the Chinese central government is undermining Hong Kong's more politically liberal traditions, despite its promise to give it a high degree of autonomy.
Democracy campaigners clashed with pro-Beijing supporters near the venue, with police separating the two sides.
Among the pro-democracy activists was Wong, who earlier told demonstrators that the only person responsible for ‘causing a public nuisance’ was ‘Xi Jinping’.
He and 25 other activists were arrested on Wednesday for ‘breaking the 'public nuisance' law’ after climbing into a golden sculpture of a bauhinia flower, Hong Kong's emblem.
The sculpture, which sits by the city's harbour front, was a gift from China and an iconic landmark symbolising the handover.
Want stories like this in your inbox?
Sign up to exclusive daily email
More Stories from Asia