Chinese President Xi Jinping faces a major test in Hong Kong after protesters stormed the semi-autonomous city's legislature and graffitied a defiant message on its walls: "Hong Kong is not China".

Beijing has trod carefully since massive protests erupted last month over a bill that would allow extraditions to the mainland, voicing support for the Hong Kong government without directly intervening and blaming "foreign forces" for the unrest.

But protesters may have pushed Beijing's patience to the limit on Monday as they ransacked Hong Kong's legislature, hung the colonial-era flag in the chamber and spray-painted anti-Beijing messages.

"It is a blatant challenge to the 'one country, two systems' bottom line. We express our vehement condemnation against this," the Hong Kong and Macao Affairs Office of the State Council, China's cabinet, said in a statement.

The protests came on the anniversary of the 1997 handover from colonial power Britain to China, which gave Hong Kong its own system of rule until 2047 -- including rights such as freedom of speech and an independent judiciary that are not enjoyed in mainland China.

The demonstrations follow years of rising concern that the Communist-led mainland is chipping away at the city's special status.

"This is a direct challenge to Xi Jinping, the Hong Kong government and the central government," Hua Po, a Beijing-based political observer, told AFP.

Xi, however, may have limited options as a direct and harsh intervention would risk spooking foreign investors in the global financial hub, according to analysts.

"Beijing needs to keep Hong Kong as an attractive place for foreign companies, for multi-nationals, as a financial centre. So they can't push too hard," said Jean-Pierre Cabestan, a China expert at Hong Kong Baptist University.

- State media coverage -

For now, Beijing's initial reaction was to call for an investigation by Hong Kong authorities into the "criminal responsibility of violent offenders" and the restoration of social order "as soon as possible".

Story continues

China's leaders have a deep fear of any sort of public challenge to their authority, and state media have avoided showing images of the protests in recent weeks as censors have controlled online discussion of the events.

But on Tuesday state television showed Hong Kong chief executive Carrie Lam's press conference, in which she condemned the use of "violence" by protesters.

Footage of protesters defacing the legislature was shown on the accounts of some media on China's Twitter-like Weibo platform, which is tightly controlled by censors.

"Communist Party censors cannot risk mainland Chinese becoming attracted to the Hong Kong alternative or the communist regime will be imperilled," said Don Tse, lead researcher at SinoInsider, a China political risk consultancy.

"The CCP, however, cannot avoid commenting on the Hong Kong situation lest it loses the opportunity to control and shape the public discourse on the mainland," Tse said.

"Thus, party censors can only afford to show the destruction of the Legislative Council but not scenes of protesters."

Hua said the Hong Kong and central governments will play up and publicise the scenes of violence to win over public opinion.

"In this way, the government can get a lot of evidence, win more public support, and find an excuse and offer evidence to violently punish these people in the future."

- 'Lower the temperature' -

The state-run Global Times condemned the "mob-like behaviour" in an op-ed piece.

While the newspaper said law and order are internal matters of Hong Kong, it added that under "a general and common-sense understanding of how justice functions, Chinese society is all too aware that a zero-tolerance policy is the only remedy for such destructive behaviour witnessed".

Analysts have said authorities could adopt the same response that they used against the 2014 pro-democracy Umbrella Movement -- arresting its leaders after the protesters failed to win any concessions.

Cabestan said Beijing could provide a mix of carrot and sticks -- ask the unpopular Carrie Lam to step down and appoint someone else to "lower the temperature", and at the same time pressure the city to prosecute the people who ransacked the legislature.

Joseph Cheng, a political analyst based in Hong Kong, said the hanging of the colonial flag and the anti-Beijing graffiti were mere "gestures of defiance rather than a genuine political action".

But Lam and Beijing can seize on it to justify a crackdown.

"That's exactly why there were a lot of voices within the pro-democracy movement demanding the maintenance of peaceful approach long before this episode last night," Cheng said.