Gustavo Petro, the former mayor of Bogota and ex-rebel fighter, has become Colombia's first left-wing president.
Mr Petro, a current senator, defeated the right-wing construction magnate Rodolfo Hernández in Sunday's run-off election.
Figures show he took 50.5% of votes, defeating his millionaire rival by a close margin of around 700,000 ballots.
The result marks a major change for the country, which for decades has been led by moderates and conservatives.
The vote was held amid widespread discontent at the way the country has been run, and there were anti-government protests last year in which dozens of people died.
The 62-year-old Mr Petro hailed what he called a "victory for God and for the people".
"May so much suffering be cushioned by the joy that today floods the heart of the homeland," Mr Petro wrote on Twitter. "Today is the day of the streets and squares."
His running mate Francia Marquez, a single mother and former housekeeper, will become the country's first black woman vice-president.
In a video posted to social media, Mr Hernandez, who ran a non-traditional campaign that relied heavily on TikTok and other social media, conceded to Mr Petro.
"I accept the results of this election," he said. "I hope that Mr Gustavo Petro knows how to run the country and is faithful to his discourse against corruption," he added.
President Ivan Duque, who was barred from seeking re-election by Colombia's term limits, said on Twitter that he had called Mr Petro to congratulate him. He added that they had "agreed to meet in the coming days to initiate a harmonious, institutional and transparent transition".
Mr Petro was a member of the now disbanded M-19 movement in the 1980s. The rebel left-wing group was one of many guerrilla organisations that waged war against the state.
He spent time in jail for illegal arms possession, before joining the political opposition where he served as both a senator and congressman as well as mayor of Bogota.
Mr Petro ran on a radical manifesto and pledged during the campaign to fight inequality by providing free university education, pension reforms and high taxes on unproductive land.
He also pledged to fully implement a 2016 peace deal that ended a 50-year long conflict with the communist guerrilla group, Farc, and to seek negotiations with the still-active ELN rebels.
At Gustavo's results party, the atmosphere is electric. On stage, and in the crowds, people here are dancing salsa - enjoying every moment of an election like no other.
In a country that experienced decades of civil conflict, Gustavo Petro's critics highlighted his role as a former rebel, arguing his economic plans would spell disaster for the country.
But his promises of inclusion and addressing poverty resonated with this deeply unequal country.
For Ana Beatriz Acevedo, who represents displaced Afro-Colombian women, the election marks a major change for the country.
"One of the problems this country has is inequality - in black and indigenous communities, among women," she said. "And they (Petro and Marquez) represent that difference - one is mixed race, one is black - and both believe in inclusion."
It's often a cliché to call elections historic but these really are - it's a huge departure for this conservative country and says a lot about how much the country has changed.
Now Colombia will have its first ever leftist leader and alongside him, the first ever black vice-president - and that speaks volumes about the desire for a different political path.
The campaign marked Mr Petro's third run for the presidency. He finished fourth in 2010, and was comfortably defeated in a run-off by Mr Duque in 2018.
While some of his proposals have startled investors - including a planned ban on new oil projects - many voters said they voted for him to tackle some of Colombia's intractable problems, such as corruption, widespread poverty and a surge in political violence.
But Mr Petro will face challenges from a fragmented congress, which includes representatives of more than a dozen parties.
"Given current levels of polarisation and existing political, economic, social and humanitarian crises, the Petro government will face significant challenges," Prof Arlene Tickner, an international relations lecturer at Universidad del Rosario in Bogotá, told the BBC.
"An important first step that has already been taken by the president-elect is to initiate efforts to build a broad national coalition in order to enhance his governability."