The second-place candidate Romulo Roux, of the centre-right Democratic Change (DC) party, trailed two points behind and has not yet accepted defeat.
Social Democrat Laurentino Cortizo won Panama's presidential election Sunday in a close race that saw a large number of voters turn out amid concerns over corruption scandals and the country's image as a money-launderer's paradise.
"I feel very happy. I won. We won. What we have to do now is join forces as a country," Cortizo told reporters shortly before the electoral tribunal confirmed his victory.
Cortizo was favored to win, with pre-election polls giving him a 10-point lead over his closest challenger, former foreign minister Romulo Roux of the Democratic Change party.
With ballots counted in 92.5 percent of polling stations, Cortizo had won 33.08 percent of the vote against 31.06 for his right-wing opponent Roux, a lead the electoral tribunal said was "irreversible" despite the close margin of fewer than 40,000 votes. Turnout was nearly 73 percent.
Trailing well behind the pair was surprise independent candidate Ricardo Lombana, a lawyer and journalist who took 19.34 percent after campaigning on an anti-corruption ticket.
Cortizo will succeed Juan Carlos Varela, whose popularity was hit by the decline in economic activity, rising cost of living, corruption scandals and crises in the health and justice sectors.
Panama's constitution limits presidents to a single five-year term.
Cortizo, a 66-year-old former agriculture minister known popularly as "Nito," said he wanted to "rescue and transform Panama" and "leave a legacy" untainted by corruption.
His supporters chanted "Nito, Nito!" as he cast his ballot in Panama City.
Corruption scandals played a significant role in election campaigning in a country struggling to shed its image as a money-laundering paradise following the Panama Papers scandal thre e years ago.
Equally damaging was the admission by Brazilian construction giant Odebrecht that it had paid $59 million in bribes in Panama between 2010 and 2014 to secure major public works contracts.
Panama is home to the strategic canal that links the Atlantic and Pacific oceans, making it a key conduit in the global maritime trading system.
Independent candidate Lombana, a 45-year-old former Panamanian consul to Washington, had hit out at the traditional parties, a popular tactic at a time when public confidence in the political establishment has been eroded by numerous scandals.
"Independent candidates have surged because citizens are fed up with what partisan politics have brought the country; they are fed up with corruption," he told reporters before casting his ballot.
'The country needs change'
In recent days, Lombana had gotten a boost from the public backing of salsa legend Ruben Blades.
While Blades did not mention Lombana by name, it was clear the singer was referring to the outsider candidate when he called on voters to pick an independent candidate promising constitutional reform in a bid to en d corruption.
"If our country continues with these corrupt institutions, it will explode," said Blades, predicting that would lead to "violent reactions."
In his campaign, Roux, 54, pointed to the economic achievements under the now-jailed former president Ricardo Martinelli when he was foreign minister.
A former chairman of the Panama Canal Authority, he has also managed to remain untainted by the multiple corruption accusations leveled against Martinelli, president from 2009-2014, that have seen the 67-year-old jailed while awaiting trial.
The new president will h ave to navigate between Chinese ambitions in the region and the United States, which jealously guards its traditional sphere of influence and the strategic canal through which around five percent of world trade passes.
While Washington gave Panama sovereignty over the canal on December 31, 1999, the 80 kilometer channel is still a major issue for Washington.
In addition to the president, Panamanians voted to elect 71 deputies, 81 mayors and 700 local lawmakers.
It was the sixth presidential election since the United States' 1989 invasion to overthrow the Manuel Noriega dictatorship.