Liberal economist Pedro Pablo Kuczynski narrowly beat right-wing populist Keiko Fujimori in Peru's presidential run-off in a photo-finish vote that the candidates split almost perfectly in half, according to results released Thursday.
The margin - just 41,000 votes - was the closest race in Peru's history.
Kuczynski, 77, emerged the winner with 50.12 per cent, while Fujimori, 41, won 49.88 per cent.
"Thank you Peru!" Kuczynski wrote on Twitter ahead of his first news conference as president-elect. "It is time to work together for the future of our country."
It took Peru's ONPE election authority nearly four days to collect and count the more than 17 million votes cast in the election, in Peru and abroad.
The final batch of 1,200 votes delivered Wednesday had been held up by poor weather in the country's interior, which had left a government helicopter unable to land.
The elections authority said that 100 per cent of votes had been processed Thursday afternoon, and 99.8 per cent had been counted. A further 0.2 per cent were still being scrutinized, the ONPE said, but could not affect the final outcome.
The victory was a stunning turnaround for a Kuczynski, who came in with just 21 per cent of the vote to Fujimori's 40 per cent in the elections' first round in April.
Analysts attributed his comeback to a coalition of parties across the political spectrum that threw their support to Kuczynski to keep Fujimori, daughter of the country's imprisoned former president, Alberto Fujimori, out of power.
Kuczynski is unlikely to gain any lasting benefit from the anti-Fujimori alliance that voted for him, as the leading left-wing candidate knocked out in the first round, Veronika Mendoza, 35, has already said her 20 parliamentarians will not support him in government.
He could also have a complicated relationship with Keiko Fujimori's Fuerza Popular party, which has a clear majority of 73 in the 130-seat chamber, despite having much in common in terms of ideology.
Keiko Fujimori and Kuczynski could easily agree on an economics minister, on a joint economic plan, including encouraging more people currently doing business informally to set up legal small businesses, political scientist Arturo Maldonado told El Comercio magazine. The two conservatives would also be able to agree a common platform on fighting crime, Maldonado said.
Keiko herself could face trouble from within her family: her brother Kenji Fujimori, a hardliner who espouses his disgraced father's politics, abstained from voting in the run-off without giving an explanation.
He had earlier declared his interest in running in the next presidential election in 2021, which would have been impossible if his sister had won, as the constitution does not allow the family members of an outgoing president to stand.
Kuczynski will take office July 28, succeeding Ollanta Humala.
Kuczynski will hope that he does not suffer the same electoral fate as his three predecessors, who were all wiped out at the polls after serving as president.
Alan Garcia (2001-2006) garnered just 6 per cent of the votes in the first round this time, while Alejandro Toledo (2006-2011) won just 1.3 per cent.
Despite more than halving poverty rates from 56 to just 23 per cent, Humala withdrew from the race as he was scoring just 1.3 per cent in opinion polls ahead of the election.
Humala was unable to overcome problems linked social conflict - such as between the lucrative mining industry and farmers over water resources - and rife corruption and nepotism.