The race to be the next president of Brazil will go to a run-off after neither of the leading candidates received more than 50 percent of the vote in the first round.
With nearly all votes counted, former President Luiz Inacio Lula da Silva received 48.3 per cent while incumbent Jair Bolsonaro got 43.3 per cent.
The pair will now face a second round on 30 October.
Voting was compulsory with more than 156 million people eligible.
Millions of people queued for hours to cast their votes and some polling stations stayed open past the scheduled closing time.
The result follows weeks of acrimonious campaigning in which the two main candidates often spent more time trading insults than laying out their policies.
During a televised debate on Thursday, President Bolsonaro called Lula, who served time in prison after being convicted on corruption charges, an "ex-inmate" and a "traitor", while Lula labelled the president "a liar".
Lula was not able to run in the last election in 2018 because he was in jail and barred from standing for office.