Taiwan passed a controversial bill Tuesday aimed at countering China's influence on the self-ruled island, less than two weeks before it goes to the polls to elect a new president.

The "anti-infiltration bill" pushed by President Tsai Ing-wen's Beijing-sceptic ruling party became law despite strong opposition from the opposition Kuomintang (KMT) party.

It bans "hostile" foreign forces from activities such as campaigning, lobbying, making political donations, disrupting social order or spreading disinformation related to elections.

Violators face a maximum five-year prison term and a fine of up to around $332,000.

KMT lawmakers displayed a placard reading "Protest evil law" during a parliamentary sit-in and abstained from voting on the bill.

They urged voters to punish Tsai's Democratic Progressive Party (DPP) at the polls on January 11.

Outside parliament, dozens of pro-China activists waved banners reading "down with Tsai Ing-wen" and "Green (DPP) Terror".

The bill has been a hot topic in the run-up to the elections as relations with China have dominated the campaign.

Tsai, who has described the vote as a fight for Taiwan's freedom and democracy, is seeking a second term against the KMT's Han Kuo-yu, a city mayor who favours warmer relations with Beijing.

She has said the bill was a response to "fears in Taiwan's society over China's infiltration from all sides".

"We passed the bill to prevent China, which is Taiwan's only threat, from using its sharp power and its capital to pollute, manipulate or sabotage Taiwan's democratic activities," said DPP lawmaker Wang Ting-yu after the bill was passed.

The Mainland Affairs Council, Taiwan's top China policy-making body, said the new law would help strengthen the island's "democratic defences".

China's "propaganda and infiltration to divide (Taiwan) are getting more serious and have threatened our national security as well as the normal operations of social order and democratic politics", it said in a statement.

In Beijing, the Taiwan Affairs Office (TAO) lashed out at the DPP over the new law.

"The DPP imposes 'Green Terror' for its political and election gains to damage cross-strait exchanges while creating hostility and confrontation between the two sides," office spokeswoman Zhu Fenglian said, according to the official Xinhua news agency.

- Rising pressure -

Beijing has stepped up military and diplomatic pressure on Taiwan since Tsai came to power in 2016, as her government refuses to acknowledge the island is part of "one China".

China still sees self-ruling, democratic Taiwan as part of its territory and has vowed to one day reunify it -- by force if necessary.

The bill comes as allegations swirl over Chinese spying and influence operations ahead of the elections.

Last month a Chinese man in Australia made explosive claims to the media that he was a spy who had taken part in infiltration operations in Taiwan, Hong Kong and Australia.

China denied the claims and accused the man of being an unemployed fraudster and fugitive.