BRASÍLIA — Voters in Brazil on Sunday ousted President Jair Bolsonaro after just one term and elected the leftist former President Luiz Inácio Lula da Silva to replace him, election officials said, a rebuke to Mr. Bolsonaro’s far-right movement and his divisive four years in office.
The victory completes a stunning political revival for Mr. da Silva — from the presidency to prison and back — that had once seemed unthinkable. It also ends Mr. Bolsonaro’s turbulent time as the region’s most powerful leader. It was the first time an incumbent president failed to win re-election in the 34 years of Brazil’s modern democracy.
For years, he attracted global attention for policies that accelerated the destruction of the Amazon rainforest and exacerbated the pandemic, which left nearly 700,000 dead in Brazil, while also becoming a major international figure of the far right for his brash attacks on the left, the media and Brazil’s democratic institutions.
More recently, his efforts to undermine Brazil’s election system drew particular concern at home and abroad, as well as worldwide attention to Sunday’s vote as an important test for one of the world’s largest democracies.
Without evidence, Mr. Bolsonaro criticized the nation’s electronic voting machines as rife with fraud and suggested he might not accept a loss, much like former President Donald J. Trump. Many of his supporters vowed to take to the streets at his command.
Yet in the hours after the race was called, far-right lawmakers, conservative pundits and many of Mr. Bolsonaro’s supporters had recognized Mr. da Silva’s victory. By 11 p.m. local time, Mr. Bolsonaro had not spoken publicly.
It was not all quiet. Truckers in the heart of Brazil’s central farming region started fires and tried to block a main highway important for the agriculture industry, according to videos posted on social media and local news reports.
Mr. da Silva won with the narrowest margin of victory for that same period, signaling the deep divide that he will confront as president. He won 50.90 percent of the vote, versus Mr. Bolsonaro’s 49.10 percent, with 99.97 percent of the votes counted Sunday night.
“I will govern for 215 million Brazilians, and not just for those who voted for me,” Mr. da Silva said in his victory speech Sunday night, reading from pages held by his new wife, whom he married this year. “There are not two Brazils. We are one country, one people, one great nation.”
Mr. da Silva, 77, a former metalworker and union leader with a fifth-grade education, led Brazil during its boom in the first decade of the century, leaving office with an 80 percent approval rating.
But years after he left office, the authorities revealed a vast government kickback scheme that had flourished during his administration. He was convicted on corruption charges and spent 580 days in prison.
Last year, the Supreme Court threw out those convictions, ruling that the judge in his cases was biased, though he was never cleared of any wrongdoing. Still, he was allowed to run for president and voters rallied behind the man known simply as “Lula.”
The scandal made him a flawed candidate, and a sizable portion of Brazil still views Mr. da Silva as corrupt. But the strong opposition to Mr. Bolsonaro and his far-right movement was enough to carry Mr. da Silva back to the presidency.
“He’s not the solution to every problem. But he’s our only hope,” said Stefane Silva de Jesus, a 30-year-old librarian, after she cast her ballot for Mr. da Silva in Rio de Janeiro.
Mr. da Silva’s victory pushes Brazil back to the left, extending a string of leftist victories across Latin America that were fueled by a wave of anti-incumbent backlash. Six of the region’s seven largest countries have now elected leftist leaders since 2018.
A left-wing firebrand who for decades made his name as a champion of the poor, Mr. da Silva now confronts significant challenges. Brazil faces environmental threats, rising hunger, a sputtering economy and a deeply divided population.
His central pitch to voters was that he would lift up the working class, which he said had been forgotten in the four years under Mr. Bolsonaro. In his speech on Sunday, he promised to fight against discrimination and for equality.
“That’s the only way we’ll be able to build a country for all, an egalitarian Brazil whose priority is the people who need the most,” he said. “A Brazil with peace, democracy and opportunity.”
Mr. da Silva’s specific plans, however, have been vague.
His stump speech revolved around expanding services for the poor, including more social welfare payments, a higher minimum wage and programs to feed and house more people. To pay for it, he said, he would raise taxes on the rich but also simply increase government spending.
How much he will be able to get done is unclear.
Mr. Bolsonaro’s right-wing party holds the most seats in Congress and a powerful centrist bloc controls both the House and Senate; the country faces worse economic conditions than during Mr. da Silva’s first administration; and the interventionist policies of Mr. da Silva’s handpicked successor as president led Brazil into a recession in 2014 from which it has still not fully recovered.
His election, however, will most likely be good news for the health of the Amazon rainforest, which is vital to the fight against climate change. Mr. Bolsonaro championed industries that extract the forest’s resources while slashing funds and staffing for the agencies tasked with protecting it. As a result, deforestation soared during his administration.
Mr. da Silva has a much better track record on protecting the forest, reducing deforestation while president. He campaigned on a promise to eradicate illegal mining and logging and said he would push farmers to use areas of the forest that had already been cleared.
On Sunday, voting at polling stations went smoothly — but, for many voters, getting there did not. Across Brazil, federal highway agents stopped hundreds of buses carrying voters to the polls and questioned people, including in regions largely supportive of Mr. da Silva.
The elections chief said his agency’s initial investigation found that the stops had delayed the buses, but that they had all still reached their intended polling stations. No voters were blocked from casting their ballots, he said.
Mr. da Silva’s victory was in part thanks to a broad coalition, from communists to centrists, as the Brazilian electorate sought stability after Mr. Bolsonaro’s volatile term, which was marked by clashes with the courts, a pandemic that killed more people than anywhere but the United States, and frequent attacks on the left, the media, academics, health professionals and the nation’s democratic institutions.
Mr. Bolsonaro, 67, has faced a variety of investigations in the Supreme Court and Congress, including for his statements attacking the election system, his handling of the pandemic and his potential involvement in disinformation operations.
So far, he has avoided any consequences from those inquiries, in part because of his immunity as president. After he leaves office on Jan. 1, those investigations could gain steam.
Mr. Bolsonaro has also had much of his activity as president shielded from government-transparency laws because his administration effectively classified many records for up to 100 years, including his vaccine status.
Mr. da Silva has vowed to declassify those records once president. “When we lift the carpet, you’re going to see the rot underneath,” he said at Friday’s debate.
Last year, Mr. Bolsonaro told his supporters there were only three outcomes to the election: He wins, he is killed or he is arrested. He then added, “Tell the bastards I’ll never be arrested.”
That sort of rhetoric raised alarms that Mr. Bolsonaro would not accept the results. He was one of the last world leaders to recognize President Biden’s victory in 2020, repeating Mr. Trump’s false claims that the election was stolen, including just two days before his first meeting with Mr. Biden earlier this year.
On Sunday, federal auditors inspected 601 polling stations to verify that their vote counts were accurately reflected in the national tally. The audit found no errors.
There is no credible evidence of fraud in Brazil’s electronic voting machines since they were introduced in 1996. Yet Mr. Bolsonaro has questioned the system for years.
Earlier this year, his criticism of the system took on new gravity when Brazil’s military joined in. Leaders of the armed forces pushed election officials for changes to the system, rattling a country that suffered under a military dictatorship from 1964 to 1985.
But eventually military and election officials agreed to a change to some tests of the voting machines on Election Day, and military leaders have since suggested they are satisfied with the system’s security.
In recent weeks, military leaders also said privately that they would not support any efforts by Mr. Bolsonaro to challenge the results.
In the week leading up to the election, Mr. Bolsonaro largely stopped talking about the voting machines and began claiming other kinds of fraud. His campaign said that many radio stations had played far more ads from Mr. da Silva, which would violate election laws. But the evidence the campaign produced was incomplete and flawed, and Brazil’s elections chief quickly dismissed the complaint.
On Friday, in an interview after the final debate, Mr. Bolsonaro was asked directly whether he would accept the vote’s results, regardless of outcome.
“There’s no doubt,” he said. “Whoever gets more votes, takes it. That’s democracy.”
Flávia Milhorance and Ana Ionova contributed reporting from Rio de Janeiro, André Spigariol from Brasília, and Laís Martins from São Paulo.