The failure of any candidate to win more than 40 percent of the vote ensured a runoff between the top two finishers, who are not related.
Some polls leading up to Sunday’s runoff had shown Mr. Alvarado Muñoz and Mr. Alvarado Quesada in a statistical dead heat in the contest to lead Costa Rica, a nation of about five million celebrated as a popular tourist destination and for its stewardship of the environment. But a survey released early last month by OPol Consultores showed Mr. Alvarado Muñoz with about a 12 percentage-point lead.
The complexion of the contest changed dramatically in January when the Inter-American Court of Human Rights ruled that its signatory nations, including Costa Rica, must legalize same-sex marriage. The court was established by the Organization of American States.
The judges’ decision came in response to a petition brought by Mr. Solís, the Costa Rican president.
The court, which is based in the Costa Rican capital, San José, also ruled that Costa Rica was obliged to extend property rights to same-sex couples.
Some countries in the region — including Argentina, Brazil, Colombia and Uruguay — have legalized same-sex marriage, though many others have not.
While the Solís administration welcomed the decision and vowed to comply with it, the court’s opinion set off a conservative backlash in Costa Rica, a traditionally Roman Catholic country. A poll by a research center at the University of Costa Rica found that a majority of respondents who knew about the ruling opposed it.
Mr. Alvarado Muñoz seized on the decision, calling it a violation of Costa Rica’s sovereignty and traditional values, and threatening to remove Costa Rica from the court’s authority should he be elected. He also railed against “gender ideology” and what he called the “secular state,” and he vowed to eliminate sex education in schools.
His hard-line positions quickly catapulted him from a seeming also-ran in a crowded field to surprise front-runner. “This demonstrates that the Costa Rican people are a people who want to defend those principles, those values,” he said in a television interview earlier this year.
In contrast, Mr. Alvarado Quesada vowed to back the court ruling on same-sex rights, setting up a clear distinction between the two candidates on what quickly became the single-most pivotal issue in the campaign.
Mr. Alvarado Muñoz’s rise also reflected the growing evangelical Christian influence in Costa Rica, which has cut into the dominance of the Catholic Church. According to a study by the Pew Research Center, 62 percent of the population identified as Catholic in 2014, down from 93 percent in 1970. That same survey also found that opposition to same-sex marriage in Costa Rica was far more pronounced among Protestants, including evangelical Christians, than among Catholics.
Javier Corrales, a professor of political science at Amherst College in Massachusetts, said that regardless of the outcome, the elections confirmed a trend that had evolved in recent years throughout Latin America: the increasing involvement by evangelical churches in politics.
“Even when they don’t win, they emerge as actors all politicians need to contend with,” he said.
“The next challenge for evangelicals in politics is how to respond to polarization,” Mr. Corrales continued. “It’s not clear that they have what is needed to promote pluralism rather than polarization.”
In mid-February, the country’s ombudsman reported having received since the first-round election “a disproportionate increase” in cases of verbal and physical aggression against lesbian, gay, bisexual, transgender and intersex people.
Shortly after casting his vote in San José on Sunday, Mr. Alvarado Muñoz vowed to lead a prejudice-free government.
“We’re going to work for everyone, and we won’t discriminate against anyone,” he told reporters, according to Reuters. “We will protect all groups that have felt vulnerable.”
The candidates also campaigned against a backdrop of other issues, including a soaring deficit, high unemployment, an increase in homicides and allegations of government corruption, all of which weighed on Mr. Alvarado Quesada’s campaign because of his association with the current administration.
Continue reading the main story