Mr. da Silva, a seasoned leftist, received 50.8% of the votes, compared to 49.2% for Mr. Bolsonaro, the incumbent far-right candidate.
Luiz Inacio Lula da Silva has won the Brazilian election by a razor-thin margin over Jair Bolsonaro.
It was the most polarised election in modern Brazilian history, putting far-right incumbent President Bolsonaro against former leftist leader Lula da Silva.
Mr. da Silva posted a simple image of his hand over the Brazilian flag with the caption “Democracy” upon his victory.
It is a surprising return to power for Mr. da Silva, 77, whose arrest in 2018 due to a corruption investigation prevented him from running in the 2018 election, opening the way for Mr. Bolsonaro’s victory and four years of far-right politics.
Mr. da Silva’s convictions were overturned, but when he decided to run for president again, he faced an uphill battle, as millions of Brazilians continued to believe he was corrupt.
After the announcement of his victory, he said, “They tried to bury me alive, but I’m still here!”
In his first address to the nation as president-elect, he pledged that “ending hunger” in Brazil will be his top priority.
This is the first occasion since Brazil’s restoration to democracy in 1985 that the incumbent president has not been reelected.
“Period of hope and the future”
All voting machines were counted by the Supreme Electoral Court of Brazil, which revealed a very tight election. Mr. da Silva received 50.9% of the votes, while Mr. Bolsonaro received 49.1%.
In the world’s fourth-largest democracy, the election was a referendum on two starkly different and opposed future visions for Brazil.
After a presidency marked by one of the world’s deadliest COVID-19 outbreaks and significant deforestation in the Amazon basin, Mr. Bolsonaro pledged to consolidate a sharp rightward tilt in Brazilian politics.
Before corruption allegations tainted the Workers’ Party, Mr. da Silva pledged greater social and environmental responsibility, recalling the rising wealth of his 2003-2010 leadership.
More than 120 million Brazilians were expected to vote electronically in the upcoming election.
There are also concerns that, should he lose, Mr. Bolsonaro may contest the election results, similar to former U.S. President Donald Trump.
He maintained for months that the nation’s electronic voting machines are susceptible to fraud, but never provided evidence.
On Sunday evening, as Mr. da Silva prepared to deliver an address at a hotel in So Paulo, Mr. Bolsonaro had not yet conceded the result.
It was the closest national election in almost three decades. With 99.5% of votes counted, a little more than two million votes separated the two contenders. In 2014, the previous tight election was decided by 3.46 million votes.
The future president, universally known as Lula, will be inaugurated on January 1, 2023.