HONG KONG -- Thousands of people protested in Hong Kong on Sunday, demanding that China's central government stay out of a political dispute in the southern Chinese city after Beijing indicated that it would intervene to deter pro-independence advocates. Police used pepper spray and batons to contain some of the demonstrators, arresting two.

The dispute centres on a provocative display of anti-China sentiment by two newly elected pro-independence Hong Kong lawmakers at their swearing-in ceremony last month.

China's top legislative panel said that Beijing must intervene to deter advocates of independence for Hong Kong, calling their actions a threat to national security. The Standing Committee of China's rubber-stamp legislature said in a statement that Beijing could not afford to do nothing in the face of challenges in Hong Kong to China's authority, the official Xinhua News Agency reported late Saturday.

On Sunday, thousands of people marched in downtown Hong Kong to voice their opposition to China's plan to step in, saying the move would undermine the city's considerable autonomy and independent judiciary.

Lee Cheuk-yan, a former pro-democracy lawmaker who was among the protesters, said Hong Kong residents were concerned that Beijing was encroaching on their relative freedoms, such as freedom of speech and expression.

"We may not agree with the two (newly elected lawmakers), their language, but we have to protect their rights because they are elected members," Lee said. "If (Beijing) can deprive them this time, they can deprive others because of other speeches or language or protest."

After the protest march, several thousand people gathered in the evening to protest outside Beijing's liaison office. Police used pepper spray and batons on demonstrators amid some scuffling.

Some protesters wore face masks and hoisted open umbrellas in the air -- symbols that were reminiscent of student-led pro-democracy demonstrations in 2014 that blocked key Hong Kong streets and attracted global attention.

Helmeted police officers with shields stood in several rows, creating a blockade against the protesters. "Open the road! Open the road!" the demonstrators chanted, as police warned them not to charge.

Senior police superintendent Tse Kwok-wai said police arrested two men, aged 39 and 57, one for obstructing police work and the other for failing to show his identity card. "Police strongly condemn protesters for breaking the law," Tse said.

Demonstrators held signs reading "Defend the rule of law" and calling for the city's Beijing-backed chief executive, Leung Chun-ying, to step down.

Some said that if China's top legislative panel issued its own interpretation on oath-taking, it would effectively undermine a Hong Kong court's ongoing review of the case.

"In (the) long run, that will damage our confidence in the court," said Alvin Yeung, a legislator.

The legislative panel in Beijing said the words and actions of the two Hong Kong lawmakers -- Sixtus Leung and Yau Wai-ching -- "posed a grave threat to national sovereignty and security," Xinhua reported.

If such a situation were to persist, the Standing Committee said, it would hurt the interests of Hong Kong's residents and China's progress. "The central government cannot sit idly and do nothing," it said.

The statement followed discussions by the committee on issuing an interpretation of an article in Hong Kong's constitution, known as the Basic Law, that covers oaths taken by lawmakers.

Last month, Leung, 30, and Yau, 25, who are from the radical Youngspiration party, altered their oaths to insert a disparaging Japanese term for China. Displaying a flag reading "Hong Kong is not China," they vowed to defend the "Hong Kong nation." Leung crossed his fingers, while Yau used the F-word in her pledge.

Their oaths were ruled invalid, but attempts at a do-over have resulted in mayhem in the legislature's weekly sessions.

Saturday's comments indicated that the Standing Committee intended to use its interpretation of the article to send a strong message against separatism -- and could ultimately lead to the democratically elected lawmakers' disqualification from office.

Such an outcome would be favourable to China's Communist leaders, who are alarmed by the former British colony's burgeoning independence movement, but is also likely to plunge their troubled relationship into fresh turmoil.

Maria Tam, a Hong Kong deputy to the National People's Congress, told reporters in Beijing on Saturday that the Standing Committee has the "final say" on the dispute, and that Hong Kong's highest court would accept the panel's interpretation as binding.

Wong reported from Beijing. Associated Press videojournalist Josie Wong in Hong Kong contributed to this report.