Former president Lula da Silva has won Brazil election, preventing far-right incumbent Jair Bolsonaro from getting a second term.
Lula has been president before, from 2003 to 2010.
Lula de Silva had 50.8 percent of the votes, while Bolsonaro had 49.2 percent.
The election authority said that Lula Silva’s victory was a mathematical certainty.
This was a comeback for the former leader, who was jailed on corruption charges in 2017.
He was released in 2019, with all convictions being legally nullified last year.
The two candidates had different visions for Brazil.
Bolsonaro promised to continue the right-wing policies of his government while Lula promised to return to the socialist policies of his previous term.
Bolsonaro had said he might not accept the results of the election if he lost.