villages in the western plains between their new possessions in the north and their base at Tayouan. Following the fall of the Ming dynasty in Beijing in 1644, Koxinga (Zheng Chenggong) pledged allegiance to the Yongli Emperor of Southern Ming and attacked the Qing dynasty along the southeastern coast of China. In 1661, under increasing Qing pressure, he moved his forces from his base in Xiamen to Taiwan, expelling the Dutch in the following year. After being ousted from Taiwan, the Dutch allied with the new Qing dynasty in China against the Zheng regime in Taiwan. Following some skirmishes the Dutch retook the northern fortress at Keelung in 1664. Zheng Jing sent troops to dislodge the Dutch, but they were unsuccessful. The Dutch held out at Keelung until 1668, when aborigine resistance, and the lack of progress in retaking any other parts of the island persuaded the colonial authorities to abandon this final stronghold and withdraw from Taiwan altogether. The Zheng regime, known as Kingdom of Tungning, is considered to be loyal to the Ming, while others argue that the regime acted as an independent ruler. However, Zheng Jing's return to China to participate in the Revolt of the Three Feudatories, a rebellion against the Qing court, ruined the regime and paved the way for the Qing invasion and occupation of Taiwan in 1683. Qing rule (1683–1895) Following the defeat of Koxinga's grandson by an armada led by Admiral Shi Lang in 1683, the Qing dynasty formally annexed Taiwan in May 1684, making it a prefecture of Fujian province while retaining its administrative seat (now Tainan) under Koxinga as the capital. The Qing government generally tried to restrict migration to Taiwan throughout the duration of its administration because it believed that Taiwan could not sustain too large a population without leading to conflict. After the defeat of the Kingdom of Tungning, most of its population in Taiwan was sent back to the mainland, leaving the official population count at only 50,000: 546 inhabitants in Penghu, 30,229 in Taiwan, 8,108 aborigines, and 10,000 troops. Despite official restrictions, officials in Taiwan solicited settlers from the mainland, causing tens of thousands of annual arrivals from Fujian and Guangdong by 1711. A permit system was officially recorded in 1712 but it likely existed as early as 1684. Restrictions related to the permit system included only allowing those who had property on the mainland, family