SAN JOSE, Costa Rica - An evangelical candidate who soared in the polls after coming out strongly against same-sex marriage and a governing party loyalist who favours it led in preliminary returns from Costa Rica's presidential election late Sunday, and appeared poised to go to a runoff.

With 68 per cent of the votes counted, Fabricio Alvarado had 25.2 per cent and Carlos Alvarado - no relation - had 21.1 per cent.

Agri-businessman Antonio Alvarez of the opposition National Liberation Party was third with 19 per cent.

If no one in the 13-candidate field finishes above 40 per cent, the top two advance to a second round of voting scheduled for April 1.

The race largely focused on gay marriage after a January ruling by the Inter-American Court of Human Rights said Costa Rica should allow same-sex couples to wed, adopt children and enjoy other rights afforded to married couples.

Fabricio Alvarado, a journalist, preacher and Christian singer, recently vaulted into first place in opinion polls after he took a strong stance against same-sex marriage, something that about two-thirds of Costa Ricans also oppose.

Carlos 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.

With so many candidates, a runoff seemed likely heading into the election.

“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.”

Political analyst Francisco Barahona told The Associated Press that the gay marriage ruling came as an “external shock” for Costa Rica, a majority Roman Catholic nation with an increasing evangelical population.

Fabricio Alvarado 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 before the polls closed.

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. “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.