Though prized by tourists drawn to its pristine beaches and jungles, Costa Rica is socially conservative and had stayed outside of the current debate that has seen several other Latin American countries accept legal unions of homosexuals.
But in January, the Inter-American Court of Human Rights -- located in Costa Rica's capital San Jose -- urged same-sex marriages to be recognised.
The decision is meant to be binding on states that are signatories to the 1969 American Convention on Human Rights, Costa Rica among them, and the current government indicated it was prone to do so.
A Costa Rican man and his Venezuelan boyfriend tried to be the first gay couple to tie the knot, but were thwarted by the national notaries' council banning its members from carrying out such celebrations.
One previously obscure presidential candidate, evangelical lawmaker Fabricio Alvarado, jumped on the issue to reject homosexual marriage. He saw his ratings in the CIEP voter survey surge from a meager three percent to around 17 percent, ostensibly making him the frontrunner.
Just behind is Antonio Alvarez, a former lawmaker and a businessman from the PLN party that is the country's biggest and most traditional. Then comes Carlos Alvarado, from the ruling PAC party.
"Given his focus on social issues in a context of heightened concern over the economy, security, and corruption, Alvarado would likely struggle to win a second-round runoff against any of the other leading candidates," the Eurasia Group political analysis firm said in a briefing note last week.
They included a corruption scandal called "cementazo" in which the state bank made irregular loans to a businessman with ties to judges and lawmakers so he could import Chinese cement, and rising security fears reflected in heightened gang activity and a record murder rate.
Those voters "who believe all politicians are corrupt" could turn to Castro, said a political analyst, Jorge Vega.
Castro's outsider status and provocative rhetoric have prompted some to liken him to Donald Trump, who confounded pundits to take the US presidency.