HONG KONG — China announced on Thursday that it had resumed diplomatic relations with Gambia, an African nation that had maintained ties with Taiwan for nearly two decades.

As Taiwan prepares to transition from a president who has deepened links with China to one who is far more cautious about cross-strait ties, the move signals a possible resumption of the contest between China and Taiwan to woo countries around the world.

China considers Taiwan to be part of its territory, and it has sought to limit the self-ruled island’s international relationships and recognition. Since 1949, when Chiang Kai-shek’s Nationalists fled to Taiwan after losing a civil war, the two sides have competed over diplomatic allies, which since the 1970s have largely flowed to Beijing.

Gambia, the smallest nation in continental Africa, has shifted between the two. After independence from Britain in 1965, it recognized Taiwan, officially known as the Republic of China. Then, after Beijing took over China’s seat in the United Nations in 1971, Gambia shifted its recognition to the People’s Republic of China.