This article is more than
2 year oldWith almost all the votes counted, Lula had won 48% against Bolsonaro's 43% - a much closer result than opinion polls had suggested.
But Lula fell short of the more than 50% of valid votes needed to prevent a run-off.
Voters now have four weeks to decide which of the two should lead Brazil.
Winning outright in the first round was always going to be a tall order for any candidate - the last time it happened was 24 years ago.
But President Bolsonaro and Lula had given their supporters hope that they could achieve just that.
Both candidates can and will claim this as a victory, though. Lula has already said that this is a "mere delay" on his way to the presidency.
For the 76-year-old former metal worker - who could not run in the 2018 election because he was in prison after being convicted on corruption charges which were later annulled - this spells a remarkable comeback.
And President Bolsonaro, whom opinion polls had shown trailing far behind Lula, will rejoice in the fact that he proved the pollsters wrong, just as he had predicted he would.
This is a drama which has been years in the making. The two men are arch-rivals and spent much of the campaign trading insults.
In the last TV debate before the vote, President Bolsonaro called Lula a thief, in reference to the corruption charges that put him in jail for 580 days before the conviction was annulled.
Lula, who has always maintained that the charges against him were politically motivated, has labelled Mr Bolsonaro a madman.
Not surprisingly, that tension has filtered down into the streets. During the nights before the vote, neighbours here in Rio could be heard shouting "Lula is a thief" and "Out with Bolsonaro" at each other.
Since the two candidates are such polar opposites, much is at stake.
Lula says he will bolster measures to protect the Amazon rainforest, while Mr Bolsonaro has argued that parts of the rainforest should be opened up to economic exploitation.
Deforestation and forest fires have soared during President Bolsonaro's time in office. Climate activists have warned that if he is re-elected, the area could reach a tipping point.
Critics point out that Lula's environmental record during his time in office - he governed Brazil from 2003 to 2010 - was far from perfect.
But with Mr Bolsonaro counting on the agricultural sector and agribusiness for votes and support, it is Lula who is the preferred choice of climate activists.
However, voters in Brazil have many other pressing concerns, such as rising food prices, which have contributed to an increase in poverty and hunger.
Mr Bolsonaro acknowledged these concerns in a statement after the results were out. "I understand that a lot of the vote was down to the situation the Brazilian people are in. They are feeling the price rises, especially those of basic goods. I do understand that there's a desire for change but some change can be for the worse," he warned.
Many voters also mentioned education and Brazil's high levels of inequality as issues they want the new president to tackle.
Much of the campaign, however, was overshadowed by concern that Mr Bolsonaro may not accept defeat after he had said that "only God" could remove him from office.
He had also cast doubts on Brazil's electronic voting system, alleging - without providing any evidence - that it was open to fraud.
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.
All eyes will now be on centrist Senator Simone Tebet, who came third in the election with 4%, and centre-left candidate Ciro Gomes, who came fourth with 3%. Both said that they would announce "in the coming days" who they would throw their weight behind for the run-off.
Lula, who seems to thrive on overcoming obstacles, has already announced that "the fight continues until the final victory, that's our motto".
Newer articles
<p>A US judge has ruled against Donald Trump getting his hush money conviction thrown out on immunity grounds.</p>