Jubilant Gustavo Petro elected Colombia's first leftist president
Stay tunned with 24 News HD Android App
With all votes counted, Petro -- the 62-year-old former mayor of Bogota -- won with 50.4 percent to Hernandez's 47.3 percent.
"As of today, Colombia is changing, a real change that guides us to one of our aims: the politics of love... of understanding and dialogue," said Petro.
Hernandez, 77, accepted the result, in which he came up short by 700,000 votes, in a Facebook live broadcast.
"I hope that Mr Gustavo Petro knows how to run the country and is faithful to his discourse against corruption," said the construction magnate, who had made fighting graft his main campaign pledge.
Petro will succeed the deeply unpopular conservative Ivan Duque, who was barred by Colombia's constitution from standing for reelection, in a country saddled with widespread poverty, a surge in violence and other woes.
Speaking to delirious supporters at his party headquarters in Bogota, Petro held out an olive branch to his opponents.
"This is not a change to deepen sectarianism in Colombia. The change consists precisely of leaving hatred behind, leaving sectarianism behind."
In another historic achievement for a country where 10 percent of the population identify as Afro-descendants, environmental activist and feminist Francia Marquez will become Colombia's first black woman vice president.
"The great challenge that all of us Colombians have is reconciliation," said the 40-year-old, who was the target of threats during a fractious campaign.
"The time has come to build peace, a peace that implies social justice."
In central Bogota, thousands of Petro supporters -- mostly young people -- rejoiced.
"I'm celebrating because finally we're going to have change ... this shows there is hope," academic Lusimar Asprilla, 25, told AFP.
Joy for Latin America
Leftist leaders in the Latin America region were quick to congratulate Petro.
"Joy for Latin America! We will work together for the unity of our continent in the challenges of a world changing rapidly," tweeted Chile President Gabriel Boric.
"The will of the Colombian people has been heard, it went out to defend the path to democracy and peace," said Venezuela's authoritarian President Nicolas Maduro, who has been branded a dictator by the opposition in his own country.
Spain's left-wing government also congratulated Petro on his "historic victory."
Meanwhile, US Secretary of State Antony Blinken sent congratulations to "the people of Colombia for making their voices heard in a free and fair presidential election."
Amid fears a tight result could spark post-election violence, some 320,000 police and military were deployed to ensure security for the 39 million registered voters.
The electoral observer mission said one of Petro's election monitors and a soldier were killed, both in the south.
Colombia is no stranger to political violence, with five presidential candidates having been murdered over the course of the 20th century.
No clear mandate
Petro will have to deal with a country reeling economically from the coronavirus pandemic, a spike in drug-related violence and deep-rooted anger at the political establishment that spilled over into mass anti-government protests in April 2021.
Almost 40 percent of the country lives in poverty while 11 percent are unemployed.
"This result does not give the new president a clear mandate to execute his policy without at least trying to address concerns from his counterpart," Sergio Guzman, president of the Colombia Risk Analysis consultancy, told AFP.
Guzman said that unless Petro learns "how to govern with the other half of the country, we can expect four years of stalemate and brinksmanship."
One major worry for many is Petro's past as a radical leftist urban guerrilla in the 1980s, who spent almost two years in jail.
Left-wing ideology is intrinsically linked in many Colombians' minds to the country's six-decade, multi-faceted conflict, leaving many to fear what a Petro presidency would represent.
He has also vowed to negotiate with Colombia's last recognized Marxist guerrillas, the National Liberation Army (ELN).
"To demonstrate he is not himself an extreme left-wing politician, it would be very complicated for him to open negotiations (with the ELN)," Elizabeth Dickinson, Colombia analyst at the International Crisis Group in Bogota, told AFP.