HONG KONG — A doctor running as an independent won the mayor’s race in Taipei, the capital, on Saturday, as Taiwan’s governing party suffered heavy losses in local elections. In response to the defeats dealt to the party, which favors closer ties with China, the prime minister resigned.

The election results, including a victory by the opposition Democratic Progressive Party in the central city of Taichung, signal that Taiwan’s governing Chinese Nationalist Party, known as the Kuomintang or K.M.T., will be hard-pressed to retain the presidency in the 2016 election.

The Kuomintang’s losses also suggest that Taiwan voters may be turning against party efforts to forge closer ties with China.

As Beijing has moved to enforce strict control over voting reforms in Hong Kong, a policy that has set off protests known as the Occupy Central movement, voters in Taiwan have said their sense of unease toward China has heightened.