ON EASTER Sunday the streets of San José erupted with revelry and relief. A long and bitter presidential election campaign had pitted a fiercely fundamentalist former gospel singer against a liberal candidate of the centre left. The liberal won decisively. A jubilant crowd waved banners of country, party and the LGBT movement, which had good reason to cheer his victory. Dancing continued into the night.

Costa Rica’s election may have been the first national election anywhere to turn on the question of gay rights. That became the biggest issue in January, after the Inter-American Court of Human Rights (IACHR), which is based in San José, issued a ruling obliging Costa Rica (and other Latin American countries) to legalise same-sex marriage. The judgment provoked an outcry in Costa Rica (most other countries barely noticed it), and propelled the two candidates with the strongest views on the issue into the run-off. Fabricio Alvarado, of the evangelical National Restoration party, vowed to disobey the order. Carlos Alvarado (pictured), of the Citizens’ Action Party, promised to carry it out with gusto.

Carlos Alvarado’s victory was an unexpected landslide. After trailing in almost every poll after the first round, held on February 4th, he defeated Fabricio (no relation) by 61% to 39%. The result does not show that ticos, as Costa Ricans call themselves, are enthusiasts for gay rights. Rather, it shows that most want a president who defends the rule of law and appears capable of dealing with the country’s many problems more than they want one who agrees with them on a divisive social issue.

Although gay people and their friends partied hardest, they are not the only ones who see Carlos Alvarado’s victory as a chance for a fresh start. Costa Ricans are angry about unemployment and inequality, and about corruption under the current president, Luis Guillermo Solís. Gridlock in congress, where a single lawmaker can block a bill unless it is supported by a two-thirds majority, has helped undermine faith in democracy.

President-elect Alvarado says he is eager to shore up support for Costa Rica’s institutions. “We lost our ability to make decisions about the future,” he said in a post-election conversation in his boyhood home. At 38, he will be the youngest president since democracy began in 1948. He is the first one in 65 years who has never belonged to one of the two parties that alternated in power until 2014, when Mr Solís took office. One of his two vice-presidents, Epsy Campbell, will be the first Afro-Costa Rican to hold the job. Expectations of the new president are high.

His rival, Fabricio Alvarado, made voters’ choice easier by adding an unnerving element of extremism to his fulminations against gay marriage. Having told voters the country needs “to put God in the government”, he made some worry that he would be guided more by the Bible than the constitution. He did not make clear how he would block the IACHR’s ruling without shredding the constitution and withdrawing from the court’s jurisdiction, something only Venezuela has recently done. Most ticos value Costa Rica’s reputation as a champion of human rights. Fabricio Alvarado also feuded with the electoral tribunal, which scolded him for failing to submit financial declarations properly.

Courting consensus

Carlos Alvarado dealt more deftly with his own electoral handicaps. He criticised Mr Solís, who belongs to the same party, and called on him to sack ministers suspected of corruption. He formed a coalition with Rodolfo Piza, the candidate of the centre-right Social Christian Unity Party, who lost in the first round. This agreement moved his policy platform to the centre and broadened his support, says Jaime Ordoñez, a political scientist.

In office, Carlos Alvarado will have to be equally deft. His coalition with Mr Piza won just a third of the seats in congress. To compensate for that, he has invited all political parties to join Costa Rica’s first “national unity government”. The aim is “not just sharing power, it’s sharing a common goal”, he says.

He needs a veto-proof majority to confront the country’s most urgent problem, a budget deficit of 6% of GDP. The main ideas for curbing it are to introduce a VAT and to rein in the fast-growing public-salary bill. To get these through, Carlos Alvarado will have to win over interest groups outside congress, such as trade unions, which blocked a plan by Mr Solís to reform public-sector salaries. Carlos Alvarado portrays his fiscal proposals as a way to make public services better, not just cheaper. He wants to spend much of his energy on issues like education and infrastructure, in part because they are “not polarising”. “From Marx to Adam Smith, [all people] hate being in traffic,” he observes.

He will also try to avoid more cultural skirmishes. One of the 93 points in the alliance agreement with Mr Piza is a promise not to tamper with Costa Rica’s restrictive abortion law.

Despite their joy, many election-night revellers realise that curing Costa Rica’s malaise will not be easy. Fabricio Alvarado was the first serious presidential candidate in the country’s democratic history to call into question its constitutional order. The next one may succeed. “We dodged a bullet,” says Kevin Casas Zamora, a former vice-president. It may not be the last.

Correction (April 6th 2018): This article has been changed to correct the percentage of the vote garnered by Fabricio Alvarado from 33% to 39%.