TAIPEI, Taiwan — Taiwan’s ruling party was handed a major defeat Saturday in local elections seen as a referendum on the administration of the island’s independence-leaning president amid growing economic and political pressure from China.

Soon after the results came in, President Tsai Ing-wen resigned as head of the Democratic Progressive Party. She will remain as president and her resignation will have no direct effect on the business of government, although the results bode ill for her re-election chances in two years.

The DPP lost the mayoral election to the Nationalist party in the southern port city of Kaohsiung, where it had held power for 20 years. The Nationalists also defeated the DPP in the central city of Taichung, home to much of Taiwan’s light industry, while Ko Wen-je, the independent mayor of Taipei, the capital, appeared on track to win a second term.

At a brief news conference at DPP headquarters late Saturday, Tsai announced she was stepping down as DPP chair and said she had refused Premier William Lai’s resignation, saying she wanted him to continue her reform agenda.

“Today, democracy taught us a lesson,” Tsai said. “We must study and accept the higher expectations of the people.”

The elections for mayors and thousands of local posts were seen as a key test for Tsai’s 2-year-old administration, which has been under relentless attack from Beijing over her refusal to endorse its claim that Taiwan is a part of China.

Tsai and the DPP won a landslide victory in 2016, but China swiftly responded by cutting all links with her government. Beijing has been ratcheting up pressure on the island it claims as its own territory by poaching its diplomatic partners and barring its representatives from international gatherings, while staging threatening military exercises and limiting the numbers of Chinese tourists visiting Taiwan.

The Nationalists, known also as the KMT, had campaigned on their pro-business image and more accommodating line toward Beijing.

Since her election, Tsai has walked a fine line on relations with China, maintaining Taiwan’s de facto independent status that the vast majority of Taiwanese support, while avoiding calls from the more radical elements of her party for moves to declare formal separation from the mainland.

Taiwanese officials had warned that Beijing was seeking to sway voters through the spread of disinformation online similar to how Russia was accused of interfering in U.S. elections.

Although domestic concerns were in the foreground, China played a major factor in voter sentiment, analysts said.

“I think part of the reason for the vote on Saturday was concern about relations between Taiwan and mainland China,” said Huang Kwei-bo, vice dean of the international affairs college at National Chengchi University in Taipei. “Their relations have slid backward.”

Saturday’s results also throw Tsai’s political future into question. While the DPP still controls the national legislature, local politicians are crucial in mobilizing support among grass-roots supporters.

“I’m afraid it will be a big challenge for her in 2020,” said Gratiana Jung, senior political researcher with the Yuanta-Polaris Research Institute think tank in Taipei.

Economic growth, employment and pension reforms were among key issues in the elections, which drew high turnout from the island’s 19 million voters. Government employees who feel slighted by pension cuts that took effect in July probably mobilized against Tsai’s party, Jung said.

Nationalist Party Chairman Wu Den-yih told reporters Saturday that his party would keep trying to avoid diplomatic friction with China and ensure smooth two-way trade.

“We hope the two sides will soon go back to a peaceful and stable trend in relations,” he said.

Chiang Kai-shek’s Nationalists rebased their government to Taiwan in 1949 amid the civil war with Mao Zedong’s Communists. They ruled under martial law until the late 1980s, when the native Taiwanese population began to take political office, mostly through the DPP.

Taiwan’s vote counting almost ends. Result shows most Taiwanese disagree to amend same-sex marriage in civil code. LGBT rights groups gather at Taipei’s Park to cheer up one another. pic.twitter.com/tabir3Xu99 — Zachary Lee (@zachary0223) November 24, 2018

Stunning pro-nuclear victory in Taiwan! 55% of voters vote to repeal nuclear phase-out! This is a massive political earthquake that will give momentum to pro-nuclear movement globally!! https://t.co/J2ysWI4xmH — Mike Shellenberger (@ShellenbergerMD) November 24, 2018

Voters on Saturday also cast ballots on 10 referendums, including one on whether to amend the civil code to include same-sex marriage — which was legalized last year — and on whether to uphold a commitment to ban nuclear energy by 2025.

And in a highly symbolic but potentially impactful referendum, voters were also asked whether they wish to compete in future international sporting events, including the 2020 Tokyo Olympics, as “Taiwan” instead of “Chinese Taipei” — the name the island is required to use at China’s insistence.

Although the IOC has already ruled out any changes and warned that Taiwan could even lose its accreditation, many see the vote as a test of support for independence and a means to fire up the DPP base.

China has already responded. Earlier this year, it forced a vote at the Asian Olympic Committee to withdraw the right of Taichung in central Taiwan to host a youth competition scheduled for next year.

The results of the referendums weren’t expected until Sunday.