SAO PAULO -- Luiz Inácio Lula da Silva has done it again: Twenty years after first winning the Brazilian presidency, the leftist defeated incumbent Jair Bolsonaro Sunday in an extremely tight election that marks an about-face for the country after four years of far-right politics.

With 99.9 per cent of the votes tallied in the runoff vote, da Silva had 50.9 per cent and Bolsonaro 49.1 per cent, and the election authority said da Silva鈥檚 victory was a mathematical certainty. At about 10 p.m. local time, three hours after the results were in, the lights went out in the presidential palace and Bolsonaro had not conceded nor reacted in any way.

Before the vote, Bolsonaro's campaign had made repeated 鈥 unproven 鈥 claims of possible electoral manipulation, raising fears that he would not accept defeat and would challenge the results if he lost.

The high-stakes election was a stunning reversal for da Silva, 77, whose imprisonment for corruption sidelined him from the 2018 election that brought Bolsonaro, a defender of conservative social values, to power.

鈥淭oday the only winner is the Brazilian people," da Silva said in a speech at a hotel in downtown Sao Paulo. 鈥淭his isn鈥檛 a victory of mine or the Workers鈥 Party, nor the parties that supported me in campaign. It鈥檚 the victory of a democratic movement that formed above political parties, personal interests and ideologies so that democracy came out victorious.鈥

Da Silva is promising to govern beyond his party. He wants to bring in centrists and even some leaning to the right who voted for him for the first time, and to restore the country鈥檚 more prosperous past. Yet he faces headwinds in a politically polarized society where economic growth is slowing and inflation is soaring.

This was the country's tightest election since its return to democracy in 1985, and the first time since then that the sitting president failed to win reelection. Just over 2 million votes separated the two candidates; the previous closest race, in 2014, was decided by a margin of roughly 3.5 million votes.

The highly polarized election in Latin America's biggest economy extended a wave of recent leftist victories in the region, including Chile, Colombia and Argentina.

Da Silva鈥檚 inauguration is scheduled to take place on Jan. 1. He last served as president from 2003-2010.

Thomas Traumann, an independent political analyst, compared the results to Biden鈥檚 2020 victory, saying da Silva is inheriting an extremely divided nation.

鈥淭he huge challenge that Lula has will be to pacify the country,鈥 he said. 鈥淧eople are not only polarized on political matters, but also have different values, identity and opinions. What鈥檚 more, they don鈥檛 care what the other side鈥檚 values, identities and opinions are.鈥

Congratulations for da Silva 鈥 and Brazil 鈥 began to pour in from around Latin America and across the world Sunday evening, including from U.S. President Joe Biden, who highlighted the country鈥檚 鈥渇ree, fair, and credible elections.鈥 The European Union also congratulated da Silva in a statement, commending the electoral authority for its effectiveness and transparency throughout the campaign.

Bolsonaro had been leading throughout the first half of the count and, as soon as da Silva overtook him, cars in the streets of downtown Sao Paulo began honking their horns. People in the streets of Rio de Janeiro鈥檚 Ipanema neighbourhood could be heard shouting, 鈥淚t turned!鈥

Da Silva鈥檚 headquarters in downtown Sao Paulo hotel only erupted once the final result was announced, underscoring the tension that was a hallmark of this race.

鈥淔our years waiting for this,鈥 said Gabriela Souto, one of the few supporters allowed in due to heavy security.

Outside Bolsonaro鈥檚 home in Rio, ground-zero for his support base, a woman atop a truck delivered a prayer over a speaker, then sang excitedly, trying to generate some energy as the tally grew for da Silva. But supporters decked out in the green and yellow of the flag barely responded. Many perked up when the national anthem played, singing along loudly with hands over their hearts.

For months, it appeared that da Silva was headed for easy victory as he kindled nostalgia for his presidency, when Brazil鈥檚 economy was booming and welfare helped tens of millions join the middle class.

But while da Silva topped the Oct. 2 first-round elections with 48 per cent of the vote, Bolsonaro was a strong second at 43 per cent, showing opinion polls significantly had underestimated his popularity.

Bolsonaro鈥檚 administration has been marked by incendiary speech, his testing of democratic institutions, his widely criticized handling of the COVID-19 pandemic and the worst deforestation in the Amazon rainforest in 15 years. But he has built a devoted base by defending conservative values and presenting himself as protection from leftist policies that he says infringe on personal liberties and produce economic turmoil. And he shored up support in an election year with vast government spending.

鈥淲e did not face an opponent, a candidate. We faced the machine of the Brazilian state put at his service so we could not win the election," da Silva told the crowd in Sao Paulo.

Da Silva built an extensive social welfare program during his tenure that helped lift tens of millions into the middle class. The man universally known as Lula also presided over an economic boom, leaving office with an approval rating above 80 per cent, prompting then U.S. President Barack Obama to call him 鈥渢he most popular politician on Earth.鈥

But he is also remembered for his administration鈥檚 involvement in vast corruption revealed by sprawling investigations. Da Silva鈥檚 arrest in 2018 kept him out of that year鈥檚 race against Bolsonaro, a fringe lawmaker at the time who was an outspoken fan of former U.S. President Donald Trump.

Da Silva was jailed for for 580 days for corruption and money laundering. His convictions were later annulled by Brazil鈥檚 top court, which ruled the presiding judge had been biased and colluded with prosecutors. That enabled da Silva to run for the nation鈥檚 highest office for the sixth time.

Da Silva has pledged to boost spending on the poor, reestablish relationships with foreign governments and take bold action to eliminate illegal clear-cutting in the Amazon rainforest.

鈥淲e will once again monitor and do surveillance in the Amazon. We will fight every illegal activity," da Silva said in his acceptance speech. "At the same time we will promote sustainable development of the communities of the Amazon.鈥

The president-elect has pledged to install a ministry for Brazil鈥檚 original peoples, which will be run by an Indigenous person.

But as da Silva tries to achieve these and other goals, he will be confronted by strong opposition from conservative lawmakers likely to take their cues from Bolsonaro.

Carlos Melo, a political science professor at Insper University in Sao Paulo, compared the likely political climate to that experienced by former President Dilma Rousseff, da Silva鈥檚 hand-picked successor after his second term.

鈥淟ula鈥檚 victory means Brazil is trying to overcome years of turbulence since the reelection of President Dilma Rousseff in 2014. That election never ended; the opposition asked for a recount, she governed under pressure and was impeached two years later,鈥 said Melo. 鈥淭he divide became huge and then made Bolsonaro.鈥

Unemployment this year has fallen to its lowest level since 2015 and, although overall inflation has slowed during the campaign, food prices are increasing at a double-digit rate. Bolsonaro鈥檚 welfare payments helped many Brazilians get by, but da Silva has been presenting himself as the candidate more willing to sustain aid going forward and raise the minimum wage.

In April, he tapped centre-right Geraldo Alckmin, a former rival, to be his running mate. It was another key part of an effort to create a broad, pro-democracy front to not just unseat Bolsonaro, but to make it easier to govern.

鈥淚f Lula manages to talk to voters who didn鈥檛 vote for him, which Bolsonaro never tried, and seeks negotiated solutions to the economic, social and political crisis we have, and links with other nations that were lost, then he could reconnect Brazil to a time in which people could disagree and still get some things done,鈥 Melo said.

___

Carla Bridi contributed to this report from Brasilia.