Taiwanese voters have swept the ruling Democratic Progressive Party's presidential candidate Lai Ching-te into power, rejecting Chinese pressure to spurn him as China says it will not give up on achieving "reunification".
Lai's party, which champions Taiwan's separate identity and rejects China's territorial claims, was seeking a third successive four year term - unprecedented under Taiwan's current electoral system.
However, in a measure of public frustration at domestic issues like the high cost of housing and stagnating wages after eight years in power, the DPP lost its majority in parliament, making Lai's job harder in passing legislation.
Lai also only won 40 per cent of the vote in Taiwan's first-past-the-post system, unlike current President Tsai Ing-wen who was re-elected by a landslide four years ago with more than 50 per cent of the vote.
Still, Lai lauded his victory.
"We've written a new page for Taiwan's history of democracy," Lai, long the frontrunner in the polls, told reporters after both his opponents conceded defeat.
Lai said he would maintain the status quo in cross-strait relations but that he was "determined to safeguard Taiwan from threats and intimidation from China".
At the same time, he emphasised the need for co-operation and dialogue with China on an equal basis to "replace confrontation" although he did not give specifics.
In the run-up to the election, China denounced Lai as a dangerous separatist and called on the people of Taiwan to make the right choice while noting the "extreme harm of the DPP's 'Taiwan independence' line".
China's Taiwan Affairs Office struck a gentler tone in its response to Lai's election and did not mention him by name, saying that the results reveal that the DPP "cannot represent the mainstream public opinion" on Taiwan.
"Our stance on resolving the Taiwan question and realising national reunification remains consistent, and our determination is as firm as rock," it said.
However, it added China will work with "relevant political parties, groups and people" from Taiwan to boost exchanges and co-operation, and "advance the peaceful development of cross-strait relations as well as the cause of national reunification".
There were jubilant scenes among a sea of cheering supporters outside Lai's campaign headquarters.
"The DPP is the only party that can truly protect Taiwan," said tattoo artist Cony Lu, 28, who broke down in tears of happiness.
"So many people are willing to stand together to preserve Taiwan's sovereignty."
Lai admitted that with losing its parliamentary majority, the DPP had "many areas that need improvement".
However, he offered an olive branch to his opponents in saying he would include talent from their parties.
Lai said he would co-operate with his electoral rivals, Hou Yu-ih of Taiwan's largest opposition party the Kuomintang (KMT) and former Taipei Mayor Ko Wen-je of the Taiwan People's Party, in resolving the problems Taiwan faces.
Taiwan's media reported the DPP won 51 seats to the KMT's 52 while the TPP received eight.
Ko appeared open to working with Lai.
"The TPP will play the role of a critical minority, without fixing who we collaborate with," Ko told reporters after conceding.
"We'll look at the issues. Whoever speaks reasonably, we will support."
During the polls, hundreds of thousands of Taiwanese youths flocked to rallies held by Ko, who has emerged as a new force in Taiwan's political landscape with roughly a quarter of the vote despite coming last.
The KMT's Hou, who Lai had portrayed as being pro-Beijing despite Hou's strong protestations, bowed to a thin crowd of supporters as he accepted defeat.
The turnout was about 72 per cent of the nearly 19 million eligible voters in the island of 23 million.
Tsai was constitutionally barred from standing again after two terms in office.