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.