Joseph Boakai has been elected president of Liberia with 50.64% of the vote, beating President George Weah who got 49.36%, according to final results announced by the election commission on Monday.
This means that Boakai won by a margin of just 20,567 votes.
Boakai, 78, is an experienced politician, having served as vice president to Ellen Johnson Sirleaf, Africa's first elected female head of state, from 2006 to 2018.
Weah had already conceded defeat on Friday evening, based on the results of more than 99.98 percent of polling stations.
The outgoing president was praised for conceding and for promoting a non-violent transition in a region marred by coups.
"Liberians have once again demonstrated that democracy is alive in the ECOWAS region and that change is possible through peaceful means," the Economic Community of West African States (ECOWAS) said in a statement.
Since 2020, ECOWAS states have seen a number of abrupt regime changes with military forces seizing power in four of the fifteen member countries, notably Mali, Guinea, Burkina Faso and Niger.
Weah was first elected six years ago, after becoming the first African footballer to win both FIFA's World Player of the Year trophy and the Ballon d'Or.
His election had sparked high hopes of change in Liberia, which is still reeling from back-to-back civil wars and the 2014-2016 Ebola epidemic.
But critics have accused him and his government of corruption and of failing to keep a promise to improve the lives of the poorest.
While his party lost, "Liberia has won," Weah had said on the radio.
Weah said he had spoken to the man he called the "president-elect" to congratulate him and urged his supporters to accept the election result.
"This is a time for graciousness in defeat," he said, adding: "Our time will come again".
The African Union (AU) sent its congratulations to Boakai on Monday: AU chairman Moussa Faki Mahamat also called on "all parties to continue to display maturity and embrace dialogue to consolidate democracy".
"In a context where democracy is undergoing turbulence in our region, this is a clear example which shows that there is always hope for democracy in West Africa," Dr Abdel-Fatau Musah, ECOWAS Commissioner for Political Affairs, Peace and Security, told RFI's correspondent Bineta Diagne. "We need inclusive elections. This will contribute to the strength of democracy."
US President Joe Biden also sent congratulations to Boakai, while praising Weah for "respecting the will of the people, and putting patriotism above politics".
Nigerian President Bola Ahmed Tinubu, commended Weah's concession saying it had averted any form of socio-political crisis.
"He has defied the stereotype that peaceful transitions of power are untenable in West Africa," Tinubu said.
Several presidential elections in the region are upcoming in 2024, including polls in Senegal, Ghana and Mauritania, as well as military-ruled Mali and Burkina Faso.