SAN JOSE, Costa Rica -- Costa Ricans voted Sunday in a presidential race shaken by an international court ruling saying the country should let same-sex couples get married.

Evangelical candidate Fabricio Alvarado recently vaulted into first place in opinion polls after he took a strong stance against gay marriage, which about two-thirds of Costa Ricans also oppose.

His closest rivals were agri-businessman Antonio Alvarez of the opposition National Liberation Party and Carlos Alvarado of the governing Citizens' Action Party.

But the outlook was cloudy because none of 13 candidates polled at more than 17 per cent and surveys indicated that more than a third of likely voters were undecided.

If no candidate reaches 40 per cent of the total vote, the top two finishers advance to an April 1 runoff.

"I see this as very divided," said Paula Rodriguez, a psychologist who cast her vote in Moravia, on the northeastern outskirts of the capital, San Jose. "I really think nobody knows what will happen."

The January decision by the Inter-American Court of Human Rights came to play a central role in the campaign. The court also ordered the country to grant same-sex couples such rights as the ability to inherit estates and adopt children.

Political analyst Francisco Barahona told The Associated Press that it came as an "external shock" for Costa Rica, a majority Roman Catholic nation with an increasing evangelical population.

Alvarado, a journalist, preacher and Christian singer, called the ruling a "sovereign violation" and saw his support balloon in the polls as socially conservative voters gravitated to that stance.

"Our message has already won. We are very happy and we hope we have convinced more undecideds," Alvarado told local media.

Carlos Alvarado, who is not related to Fabricio Alvarado, was the only major candidate to openly back gay marriage and picked up some support recently from socially liberal voters. Trained as a journalist, he got his start in politics as communications director for Citizens' Action and also was labour minister under current President Luis Guillermo Solis.

Alvarez, a two-time president of the Legislative Assembly and a Cabinet minister under the first presidency of Oscar Arias in 1986-1990, said he opposes gay marriage but backs recognizing certain other rights for gay couples.

Some voters had other issues on their minds. Carlos Morales, who cast a ballot in the Guadalupe district of San Jose, said his biggest concern is that the next president manage the government's deficit without creating new taxes.

"They say the government is broke and to fix that they are going to impose more taxes on us," Morales said shortly before polls closed Sunday evening. "But I think people here are already living very tightly. Everything is very expensive, and that would hurt us all."

Voters were also selecting the 57 delegates that make up the Assembly.