Centre-left candidate Laurentino Cortizo has been declared the winner of Panama's presidential election.
In an unexpectedly close race, Mr Cortizo finished two percentage points ahead of his centre-right rival, Rómulo Roux.
Mr Roux has yet to concede, citing reports of voting irregularities.
The elections have been dominated by pledges to fight corruption and to tackle Panama's image as a money-laundering country.
The country's electoral tribunal says 95% of ballots have been counted, with Mr Cortizo winning 33% of votes, followed by Mr Roux with 33%.
Official results are expected to be announced on Thursday, though the tribunal said the result was "irreversible" despite a close margin of fewer than 40,000 votes.
"I owe it to you, to all Panamanians," Mr Cortizo told reporters.
"I will work hard, fight and I will serve my country with humility, dignity and honesty".
The presidential race is Panama's sixth since a US invasion ousted Manuel Noriega in 1989.
Who is Laurentino Cortizo?
Laurentino "Nito" Cortizo, 66, is the candidate for Panama's Democratic Revolutionary Party (PRD).
His party, founded by military ruler Omar Torrijos in 1979, has been out of power since 2009.
Mr Cortizo was educated in the US and has previously served as minister of agriculture.
He has also held roles at the regional Organisation of American States, and worked in the construction and livestock sectors.
What have been the election's main talking points?
Corruption has been at the forefront of the presidential race, spurred by scandals surrounding Odebrecht. The Brazilian construction firm was found guilty of giving illegal payments to 17 Panamanian officials.
Mr Cortizo has vowed to fight corruption by reforming laws that govern how public contracts are awarded.
Other major issues have included rising unemployment, Panama's education system, and the state of water utilities and rubbish collection in the capital, Panama City.
Mr Cortizo has also expressed a desire to strengthen the country's ties with America.
"The United States is our strategic partner, our main strategic partner," Mr Cortizo told news agency Reuters. "This relationship has to improve."