Nobel Peace Prize winner Oscar Arias is to become Costa Rica's president for the second time, after his rival in a close-fought election conceded defeat.
Mr Arias is seen as untainted by scandal
An election was held nearly a month ago, but Otton Solis has only now given up after losing a manual recount and a series of legal challenges.
Mr Arias is committed to taking Costa Rica into a controversial free trade pact with the United States.
His prize was for leading talks to end two 1980s Central American civil wars.
Mr Arias, 65, had enjoyed a big lead over his rival in opinion polls.
But far from the easy victory that had been predicted for him, the election on 5 February became Costa Rica's hardest-fought vote in the last four decades, with the two leading candidates virtually neck-and-neck.
The election comes amid wide disillusionment with politics after a string of corruption scandals in the country.
Mr Arias - who was in office between 1986 and 1990 - is not among them, and many Costa Ricans see him as a politician untainted by the recent scandals. But his critics describe him as arrogant.
He won the Nobel Peace Prize in 1987 for spearheading talks that led to the end of civil wars in Nicaragua and El Salvador.
He says he wants Costa Rica to join the Central American Free Trade Agreement (Cafta) with the US.
Costa Rica is the only country in the region which has not ratified the deal, which is set to come into effect later this year.
Mr Solis wanted some of the deal to be renegotiated, arguing that in its current form it would exacerbate poverty and hurt small-scale farmers.