China's parliament passed an interpretation of Hong Kong's Basic Law on Monday that says lawmakers must swear allegiance to the city as part of China, Beijing's most direct intervention in the territory’s legal and political system since the 1997 handover.

The ruling is expected to bar two activist lawmakers from taking office in Hong Kong. The prospect of the ruling had sparked protests in the former British territory that returned to Chinese rule in 1997.

The official Xinhua news agency reported that China's parliament ruled at the end of a regular bimonthly session that the pair of pro-independence lawmakers could not assume their positions in Hong Kong's Legislative Council if they refused legal procedures when taking oath of office.

The intervention relates to Article 104 of the city's mini-constitution, which states that lawmakers must swear allegiance to Hong Kong as part of China when they take office.

It came even before a Hong Kong court had ruled, representing some of the worst privately held fears of senior judges and some government officials in Hong Kong, according to sources close to them.

The move was expected to enrage Hong Kong democracy activists further, a day after hundreds of demonstrators clashed with police in running battles around China's representative office in Hong Kong.

READ: Hong Kong police use pepper spray at anti-China protest

The scenes on Sunday night were reminiscent of pro-democracy protests in late 2014 that paralysed parts of the Asian financial centre and posed one of the greatest political challenges to the central government in Beijing in decades.

Britain returned Hong Kong to Chinese control in 1997 under a "one country, two systems" formula that gave the territory wide-ranging autonomy, including judicial freedom guided by a mini-constitution called the Basic Law.

The rift between Hong Kong and Beijing has deepened since Yau Wai-ching, 25, and Baggio Leung, 30, pledged allegiance to the "Hong Kong nation" and displayed a "Hong Kong is not China" banner during a swearing-in ceremony for the city's legislative council in October.

Leading members of China's parliament said on Saturday the two Hong Kong lawmakers-elect had damaged the territory's rule of law and posed a grave threat to China's sovereignty and security.

The Hong Kong Bar Association has said an intervention by Beijing now, while a local court was hearing the case, would deal a severe blow to the city's judicial independence and undermine international confidence in Hong Kong's autonomy.

The oath-taking controversy made waves in the former colony, where the topic of independence from China was once regarded as taboo but has come to the fore since the pro-democracy protests in 2014 that failed to secure any concessions from Beijing.