HONG KONG — Taiwanese President Tsai Ing-wen announced on Saturday plans to step down as party chairwoman following sweeping midterm losses against a rival party that favors closer relations with China.

The nationwide elections for local offices were seen as a referendum on Tsai’s administration two years after she swept into power in a landslide and became Taiwan’s first female president, promising to distance the island democracy from the mainland Communist Party’s pull and revitalize its lackluster economy.

But her economic stewardship came under criticism as she sought unpopular labor restructuring and pension cuts, while wage growth — which has been flat since the 1990s — never materialized. Meanwhile, the Chinese government launched personal attacks against Tsai, held military drills near the island and worked to isolate Taiwan by flipping Latin American countries’ diplomatic allegiances from Taipei, Taiwan’s capital, to Beijing.

The election was overshadowed by allegations from Tsai’s Democratic Progressive Party that China was seeking to influence the election through a misinformation campaign on social media and by illegally financing pro-China publications. But Tsai said Saturday night that she took “full responsibility” for the DPP’s losses and acknowledged the reversal reflected the people’s will on a day when Taiwanese queued for hours to cast their ballots.

“Today, democracy taught us a lesson,” Tsai said Saturday night, when her DPP lost mayoral races in several major cities to the Kuomintang nationalist party.

Tsai announced she would quit as DPP chairwoman but is expected to serve out her term as president until 2020.

It’s not immediately clear how the ascendancy of the China-friendly Kuomintang might affect policy in Washington. Under the Trump administration, which has taken a harder line against Beijing, high-ranking State Department and Pentagon officials have argued for greater U.S. support for the island ally in the form of regular weapons sales and diplomatic backing in the international arena.

The United States “congratulates the people of Taiwan for once again demonstrating the strength of their vibrant democratic system through a successful round of elections,” the State Department said in a statement to Taiwan’s official Central News Agency.

The election also dealt a resounding referendum defeat for a measure that would have made Taiwan the first place in Asia to legalize same-sex marriage.

Gay rights activists had been optimistic after a Taiwanese court in 2016 ruled as unconstitutional the language in the island’s civil code defining marriage as only between a man and a woman. Tsai, who had once voiced support for same-sex marriage, backed away in recent months as her approval rating fell and the measure became a wedge issue that fired up older conservative voters.

That same electoral group, which is typically more China-friendly, likely played a key role in also striking down a referendum on whether Taiwan should apply to participate in the 2020 Olympic Games as “Taiwan” rather than “Chinese Taipei,” as it has for decades under a diplomatic agreement. 

Beijing has considered Taiwan a breakaway territory since the Kuomintang lost a civil war in 1949 and fled the mainland for the island. In recent decades, the Kuomintang has favored closer ties with China, while China views the independence-leaning DPP as anathema.

Beijing has excoriated Tsai for refusing to officially acknowledge that Taiwan is part of China, even though she has been moderate in the context of domestic Taiwanese politics, often pushing back against calls to declare independence.

A Chinese spokesman on Taiwan issues, Ma Xiaoguang, welcomed the election results and said it showed the Taiwanese people wanted closer ties with Beijing.

China “will continue to firmly oppose separatist elements advocating ‘Taiwan independence’ and their activities, and unite the people of Taiwan to take a path of peaceful development in cross-strait relations,” he said.