Costa Rica's President Oscar Arias has announced that his country has broken diplomatic ties with Taiwan after 60 years and formed relations with China.
Mr Arias said he made the decision "thinking of all the Costa Ricans"
Mr Arias said Costa Rica needed to develop closer ties with China in order to attract foreign investment.
Taiwan and China have been governed separately since the end of a civil war in 1949, and both still compete for diplomatic recognition.
Taiwan's foreign minister has offered to resign over the Costa Rican move.
The switch leaves Taiwan with just 24 allies, compared to China's 170.
China regards Taiwan as a breakaway province which it has vowed to retake. It refuses to have diplomatic ties with nations that recognise Taiwan.
"We will immediately end our ties with Costa Rica and terminate all co-operation programmes," said Taiwanese Foreign Minister James Huang.
Mr Huang said he believed Costa Rica to be an isolated case, but added that Taiwan must be careful to maintain its diplomatic links.
"I've asked our embassies to take extreme precautions against any further pressure by the Chinese communists," said Mr Huang.
At a news conference, the Costa Rican president thanked Taiwan for its "solidarity and co-operation" but said he had taken the decision "thinking of all the Costa Ricans".
"We are looking to strengthen the commercial ties and attract investment. China is the most successful emerging economy in the world," said President Arias.
Analysts say Taiwan is fearful that Costa Rica's shift in allegiance to Beijing could prompt other Latin American nations such as Nicaragua and Panama to follow.