By Venus Wu and Sue-Lin Wong

HONG KONG/BEIJING (Reuters) - China's parliament passed a ruling on Monday that effectively bars two elected Hong Kong pro-independence politicians from taking office, Beijing's most direct intervention in the territory's legal and political system since the 1997 handover.

The rare move by Beijing came after Yau Wai-ching, 25, and Baggio Leung, 30, pledged allegiance to the "Hong Kong nation" and displayed a banner declaring "Hong Kong is not China" during a swearing-in ceremony for the city's Legislative Council in October.

The National People's Congress in Beijing ruled that lawmakers must swear allegiance to Hong Kong as part of China and that candidates would be disqualified if they changed the wording of their oath of office or if they failed to take it in a sincere and solemn manner.

The prospect of the ruling sparked protests in the former British colony on Sunday and it is now on high alert for any repeat of the weekend clashes. Members of the city's legal profession are planning a rare silent march on Tuesday night amid pressure for them to take even stronger action.

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

The protests on Sunday night were reminiscent of pro-democracy demonstrations 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.

"This incident shows us the Basic Law is a handicapped legal document and the so-called mini-constitution can be amended and controlled by the Chinese Communist Party at will," said Joshua Wong, 20, one of the leaders of the 2014 protests.

Foreign diplomats were watching closely, stressing the importance of the rule of the law to the city's international reputation.

Britain said it was concerned.

"We urge the Chinese and Hong Kong (special administrative region) governments, and all elected politicians in Hong Kong to refrain from any actions that fuel concerns or undermine confidence in the one country, two systems principle," a Foreign Office spokeswoman said in a comment echoed by the U.S. State Department.

The State Department said it was "disappointed" by recent developments and the United States strongly supported the "critically important role" of the legislative council and independent judiciary in protecting the one country, two systems framework.

"(A)n open society with the highest possible degree of autonomy and governed by the rule of law is essential for Hong Kong’s continued stability and prosperity," State Department spokesman Mark Toner told a regular news briefing.

While the decision effectively bars the two Hong Kong politicians from being sworn in, a court in the city must still rule on the case in a judicial review, taking Beijing's decision into consideration.

The promotion of independence has long been taboo in Hong Kong amid fears in Beijing it could spread among other activists and challenge the central government's rule.

"GRAVE DANGERS"

"The nature of Hong Kong independence is to split the country. It seriously violates the one country, two systems policy," said Li Fei, chairman of the parliament's Basic Law Committee.

"The Central Government is highly concerned about the grave dangers the Hong Kong independence forces bring to the country and to Hong Kong."

Hong Kong leader Leung Chun-ying, who has governed during some of the city's most violent and divisive times in decades, said his government would fully implement China's interpretation of the mini-constitution.

But Legislative Council president Andrew Leung said the Hong Kong judicial review needed to be completed before confirming if the pair were disqualified.

Simon Young, a professor at Hong Kong University's law school, said he was still evaluating the ruling but it did seem to bar Leung and Yau from taking office.

"I do worry we are only going to see more interpretations, and attempts by the NPC to flesh out local laws, if they really want to stop the separatists," Young told Reuters, referring to China's parliament.

The Basic Law grants China's NPC a power of interpretation above Hong Kong's highest court. While it has made four other rulings since 1997, this ruling is its first move to preempt an ongoing Hong Kong court case.

Hong Kong Justice Secretary Rimsky Yuen said he still believed the oath-taking controversy could be resolved locally, but he also had every confidence that the city's judiciary would uphold the rule of law.

Beijing's decision represents some of the worst privately held fears of senior judges and some government officials in Hong Kong, according to sources close to them.

Chinese Foreign Ministry spokesman Lu Kang said at a regular press briefing he hoped the international community would see the decision reflected the will of the Chinese people.

James To, a lawmaker with the Democratic Party, said the central government had undermined Hong Kong's judicial process.

"In future, people's confidence in one country, two systems will worsen," To said.

(Reporting by Michael Martina and Sue-Lin Wong in BEIJING, Greg Torode, Venus Wu and Donny Kwok and James Pomfret in HONG KONG and David Brunnstrom in WASHINGTON; Writing by Anne Marie Roantree; Editing by Paul Tait, Nick Macfie and Andrew Hay)