Brazil has taken a turn to the left as former president Luiz Inácio Lula da Silva beat far-right incumbent Jair Bolsonaro in the presidential election.
After a divisive campaign which saw two bitter rivals on opposite sides of the political spectrum go head to head, Lula won 50.9% of the votes.
It was enough to beat Jair Bolsonaro, whose supporters had been confident of victory.
But the division that this election has highlighted is unlikely to vanish.
It is a stunning comeback for a politician who could not run in the last presidential election in 2018 because he was in jail and banned from standing for office.
He had been found guilty of receiving a bribe from a Brazilian construction firm in return for contracts with Brazil's state oil company Petrobras.
Lula spent 580 days in jail before his conviction was annulled and he returned to the political fray.
"They tried to bury me alive and here I am," he said, kicking off his victory speech.
Since the announcement, congratulations have been coming in from leaders around the world, including US President Joe Biden, who noted the result came "following free, fair, and credible elections".
He added he was looking forward to continuing cooperation.
Russian President Vladimir Putin also offered his "sincere congratulations", saying the results had confirmed Lula's "impressive political authority".
India's Narendra Modi said he looked forward to deepening ties, while UK Prime Minister Rishi Sunak tweeted: "I look forward to working together on the issues that matter to the UK and Brazil, from growing the global economy to protecting the planet's natural resources and promoting democratic values."
Lula embraced his wife Rosangela after his victory
77 years old
Former metal worker
President from 2003-2010
Imprisoned in 2018 but conviction was later thrown out
Opinion polls suggested from the start that he would win the election, but when his lead in the first round was much narrower than predicted, many Brazilians started to doubt their accuracy.
A moment in history for Brazil as Lula returns
In pictures: Lula beats Bolsonaro
Jair Bolsonaro's backers - encouraged by their candidate's allegations that "the establishment" and the media were against him and therefore underplaying his support - had complete faith in his victory.
The left-wing leader's victory is likely to rankle with these Bolsonaro fans, who routinely label Lula "a thief" and argue that the annulment of his conviction does not mean he was innocent, just that the proper legal procedure was not followed.
And while Jair Bolsonaro has lost, lawmakers close to him won a majority in Congress.
This means that Lula will face stiff opposition to his policies in the legislative body when he takes office on 1 January.
But Lula, who served two terms in office between January 2003 and December 2010, is no stranger to forging political alliances.
As his vice-presidential running mate he chose former rival Geraldo Alckmin, who ran against Lula in previous elections.
His strategy of creating a "unity" ticket seems to have paid off and drawn voters into the fold who may not have consider otherwise casting a ballot for his Workers' Party.
In his victory speech, Lula struck a conciliatory tone, saying he would govern for all Brazilians and not just those who voted for him.
"This country needs peace and unity. This population doesn't want to fight anymore," he said.
Jair Bolsonaro has yet to concede. The campaign had in part been so tense because the far-right president had cast doubts - without offering any evidence - on the reliability of Brazil's electronic voting system.
This fomented fears he might not accept the result if it went against him.
A day before the second round however, he stated that: "There is not the slightest doubt. Whoever has more votes, takes it [the election]. That's what democracy is about."
Five key facts about Bolsonaro
67 years old
Former army captain
Running for a second consecutive term
Has cast unsubstantiated doubts on the trustworthiness of Brazil's electronic voting system
On election day itself, buses carrying voters to the polls were stopped by police in what Lula's campaign said was an attempt to prevent them from voting.
The head of the electoral court, Alexandre de Moraes, ordered the highway police to lift all roadblocks and checks.
He said that while some voters had been delayed, none had been prevented from voting. But the incidents raised tensions considerably.
Now there is much expectation as to when and what Mr Bolsonaro will say now that it is official that fewer votes were cast for him than for Lula.
The election has not just been closely watched in Brazil, but also abroad, with environmental activists in particular worried that another four years of a Bolsonaro government would have led to further deforestation in the Amazon rainforest.
Lula referred to these fears in his victory speech saying that he was "open to international co-operation to protect the Amazon".
"Today we tell the world that Brazil is back. It is too big to be banished to this sad role of global pariah," he added in a dig at his rival.
But at the heart of his speech was a promise to tackle hunger, which has been on the rise in Brazil and which is affecting more than 33 million.
Key to Lula's popularity during his first two terms in office was lifting millions of Brazilians out of poverty.
But in a post-pandemic economy, finding the finances to recreate that feat will not be an easy task, especially if he is hampered by a hostile Congress.