Ex-guerrilla Gustavo Petro was elected the first ever left-wing president of Colombia on Sunday, after beating millionaire businessman Rodolfo Hernandez in a tense and unpredictable runoff election.

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.

A man works at a polling station in Bogota, on June 18, 2022, a day before the presidential runoff election
A man works at a polling station in Bogota, on June 18, 2022, a day before the presidential runoff election AFP / Juan BARRETO

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.

Colombian presidential candidate for the 'Colombia Humana' party and the Historic Pact coalition, Gustavo Petro (L), and Colombian independent presidential candidate Rodolfo Hernandez
Colombian presidential candidate for the 'Colombia Humana' party and the Historic Pact coalition, Gustavo Petro (L), and Colombian independent presidential candidate Rodolfo Hernandez AFP / Raul ARBOLEDA

"This is not a change to deepen sectarianism in Colombia. The change consists precisely of leaving hatred behind, leaving sectarianism behind."

He added: "We want a Colombia that through its diversity is one Colombia."

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.

Soldiers stand guard at a checkpoint on a road entering Bogota, on June 18, 2022, a day before the presidential runoff election
Soldiers stand guard at a checkpoint on a road entering Bogota, on June 18, 2022, a day before the presidential runoff election AFP / Juan BARRETO

"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.

Maverick candidate Rodolfo Hernandez arrives at a polling station in the northern city of Bucaramanga to cast his vote in Colombia's presidential runoff on June 19, 2022
Maverick candidate Rodolfo Hernandez arrives at a polling station in the northern city of Bucaramanga to cast his vote in Colombia's presidential runoff on June 19, 2022 AFP / Raul ARBOLEDA

Leftist leaders in the Latin America region were quick to congratulate Petro.

"Gustavo Petro's victory is historic. Colombia's conservatives have always been tenacious and tough," Mexico President Andres Manuel Lopez Obrador wrote on Twitter.

A man votes during the Colombian presidential runoff election, in Bogota on June 19, 2022, with voters filled with uncertainty over deciding between ex-guerrilla Gustavo Petro and millionaire businessman Rodolfo Hernandez
A man votes during the Colombian presidential runoff election, in Bogota on June 19, 2022, with voters filled with uncertainty over deciding between ex-guerrilla Gustavo Petro and millionaire businessman Rodolfo Hernandez AFP / Juan BARRETO

"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."

"Colombia has elected a new president, has chosen equality, social and environmental justice," Prime Minister Pedro Sanchez tweeted.

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.

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.