Jair Bolsonaro, Brazil's hard-Right president, has defied the polls to force a run-off in the country’s presidential election, leaving conservatives celebrating and the resurgent Left with “a bitter taste” following Sunday’s vote.
Mr Bolsonaro was trailing by as many as 14 points to leftist former president Luiz Inacio Lula da Silva, and was in danger of being voted out in the first round after the public appeared to reject his handling of the economy and dismissive attitude towards the pandemic.
But the president came within just five points of Mr da Silva, known colloquially as Lula, whom he will face in a high-stakes runoff on Oct 30.
The count showed Lula with 48.4 per cent of the vote to Mr Bolsonaro's 43.2 per cent, according to Brazil's electoral authority. Nine other candidates split the rest.
"This is a big defeat for the democratic centre that saw its voters migrate to Bolsonaro," said Arilton Freres, director of the Curitiba-based Instituto Opiniao. "Lula starts ahead, but it won't be easy for him."
The result "leaves a bitter taste for the Left, if we consider what the polls were showing", said Rafael Cortez, who oversees political risk at consultancy Tendencias Consultoria.
Sunday was also a strong election night for allies of Mr Bolsonaro who won the most seats in both chambers of Congress, highlighting the enduring strength of his conservative movement.
His Right-wing Liberal Party (PL) won 99 seats in the 513-member lower house, up from 77, and Right-leaning parties allied with Bolsonaro now control half the chamber.
The bigger surprise in Sunday's vote was in the senate where Bolsonaro's party won 13 of the 27 seats up for grabs, with two more possible in second-round runoffs, a party spokesman said.
On Monday, Mr Bolsonaro was defiant.
"Many people were carried away by the lies propagated by the research institutes," he wrote on Twitter. "All their predictions were wrong and they are already the biggest losers of this election. We beat that lie and now we're going to win the election."
The vote was virtually free from the political violence that many had feared. Alexandre de Moraes, the Supreme Court justice who also leads the electoral authority, congratulated Brazil for the "safe, calm, harmonious and peaceful" election that demonstrated its democratic maturity.
There is still a difficult month ahead, however.
The difference between Lula and Mr Bolsonaro in the first round amounted to 6.1 million votes, with the former picking up 57 million and the latter 51 million. Third and fourth place candidates Simone Tebet and Ciro Gomes together won 8.5 million votes, while more than 30 million people abstained.
The overall population is around 215 million.
"Brazil is much more polarised than many people thought, and governing will be difficult for whoever wins," said Brian Winter, vice-president for policy at the Americas Society/Council of the Americas.
"I think the next few weeks will put heavy strain on Brazil's democracy as these two men fight it out. Expect an ugly race that will leave scars."
The past four years have been marked by Mr Bolsonaro’s incendiary speeches, testing of democratic institutions, widely criticised handling of the pandemic and the worst deforestation of the Amazon rainforest in 15 years.
But he has built a devoted base by defending conservative values and presenting himself as protecting the nation from leftist policies that he says infringe on personal liberties and produce economic turmoil.
Extensive social welfare programme
Lula is credited with building an extensive social welfare programme during his 2003-2010 tenure that helped lift tens of millions into the middle class and saw exports surge amid the global commodities boom.
He is also remembered for his party's involvement in corruption scandals and his own convictions, which were later annulled by the Supreme Court that ruled the judge had been biased. That freed him from imprisonment and cleared the way for his presidential run.
The Right's positive night extended to races for governorships and congressional seats, especially candidates with Mr Bolsonaro's endorsement. His former infrastructure minister won the race to govern Sao Paulo. Claudio Castro, the governor of Rio de Janeiro, vanquished his opponent to win re-election outright.
Sergio Moro, the former judge who temporarily jailed Lula and was Mr Bolsonaro’s former justice minister, defied polls to win a senate seat.
Overall, Mr Bolsonaro's Liberal Party will surpass Lula’s Workers' Party to become the biggest in the senate and the lower house.