The vehicle was being driven by two Costa Ricans who were not paramedics and who had no license to drive an ambulance, the public security ministry said in a statement. They, too, were arrested.
Police stopped and searched the ambulance just after dawn in the town of Peñas Blancas de la Cruz, on the border. The Africans were found to have entered Costa Rica illegally.
Central America is a major waypoint for undocumented migrants trying to enter the United States. Not only migrants from Latin America pass through the isthmus but also ones from Africa, Asia and the Middle East.
In early November, Costa Rica dismantled a people-smuggling ring that transported undocumented migrants through the region.
Currently there are nearly 8,000 U.S.-bound Cuban migrants stranded in Costa Rica since Nicaragua mid-November closed its border to them.
Under a deal between some Central American nations and Mexico last week, 180 of those Cubans are to be flown next week to El Salvador to continue their journey, with others expected to follow.
Recommended: Cuban migrant airlift from Costa Rica starts Jan. 12