Costa Rica saw an "unprecedented" migratory flow into the country this year, with tens of thousands of mainly Cubans, Haitians and Africans seeking passage to the United States, the government said.

"More than 26,000 irregular migrants entered the country" from the southern border with Panama, the ministry of communication said in a statement, released on Sunday.

Most of them arrived this year, though up to 8,000 were Cubans who became stranded in Costa Rica in late 2015 when neighboring Nicaragua closed its border to them.

Since then, the biggest flow has been that of Haitians, along with smaller numbers of Africans.

Many of them also face difficulties trying to get through Nicaragua, staying in shelters and camps in northern Costa Rica while turning to people-smugglers for help to cross the border. They have been given temporary visas, but no right to work.

"This could have been the biggest migratory crisis in the country, but it was an opportunity for Costa Rica to show the world its vocation in defending human rights," Communication Minister Mauricio Herrera said.