The election is now going into a second round in which left-winger Luiz Inácio Lula da Silva will face far-right incumbent Jair Bolsonaro.
With almost all the votes counted, Lula had won 48% against Bolsonaro's 43% - a much closer result than opinion polls had suggested.
Here’s everything you need to know.
What is a runoff?
Despite winning the majority of the votes, Lula fell short of the more than 50% of valid votes needed to prevent a run-off.
Brazil’s election authority said the result made a second-round vote between the two candidates a mathematical certainty.
Voters now have four weeks to decide which of the two should lead Brazil.
Winning outright in the first round has not happened in 24 years, with run off votes between the top two candidates common in Brazilian elections.
Nine other candidates in the election now drop out and voters will once again go to the polls.
Brazil elections: When will the runoff vote take place?
The runoff vote will take place on October 30.
What has each candidate said about the first round?
Many had feared that President Bolsonaro would contest the election following unfounded claims that the election had been rigged.
Spaking at a post-vote press conference, Lula referred to the scheduled Oct. 30 runoff vote against Bolsonaro as “extra time” in a soccer game.
“I want to win every election in the first round. But it isn’t always possible,” he said.
Lula added "The fight continues until the final victory, that's our motto.”
Bolsonaro told reporters in capital city Brasilia that he understood there was “a desire for change” among the population, hard hit by the economic crisis and high inflation. “But certain changes can be for the worse.”
The president, who has repeatedly questioned the reliability of the country’s electronic machines, did not challenge Sunday night’s results, although he said he was waiting for more information from the Defence Ministry.
With the result much more favourable to him than predicted, he is now likely to concentrate more on how to sway those voters who cast their ballot for one of the other nine candidates who were eliminated in the first round.