Taiwan's China-friendly ruling party lost a slew of traditional strongholds in local elections on Saturday, triggering the resignation of the island's premier and the cabinet.

The worse-than-expected showing underlined the growing unpopularity of the government of President Ma Ying-jeou, which has been trying to forge closer ties with China.

China is Taiwan's largest trading partner, but Beijing has never renounced the use of force to take back what it deems a breakaway province.

The ruling Kuomintang (KMT) shed seats across the island, including in the capital Taipei, where Ko Wen-je, the candidate backed by the pro-independence opposition party was elected as the next mayor, ending the ruling party's 16-year hold on the city.

The local elections, held less than two years ahead of a presidential poll, were the first chance for voters to make their views felt since thousands of young people occupied parliament in March in an unprecedented demonstration against a planned trade pact calling for closer ties with Beijing.

The departure of premier Jiang Yi-huah just hours after polls closed left President Ma, who is also KMT chairman, to rebuild a government.

A crowd of several thousand Ko supporters filled the wide city street outside of his campaign headquarters, with rock music blaring out of loud speakers.

Kuo Hsin-tai, a 40-year-old photocopy shop owner and supporter of Ko, said he had grown disillusioned with the Kuomintang.

"They're making Taiwan far too dependent on the mainland. Their policy-making muscle is far too focused on cross-strait ties and not nearly enough on raising the standard of living of the average Taiwanese person."

China's Taiwan Affairs Office, which is in charge of Taiwan matters for Beijing, said in a statement following the vote that it hoped "cross-strait compatriots" would jointly safeguard the peaceful development of cross-strait relations.

Al Jazeera and Reuters