Far-right Congressman and former Army captain Jair Bolsonaro has won nearly half the votes in Brazil's first-round presidential election.
In what is likely to be a deeply polarising runoff, Bolsonaro, an outspoken apologist for Brazil's 1964-1985 military dictatorship, will now face leftist Fernando Haddad, the former mayor of Sao Paulo, in a second round of voting on October 28.
Dubbed a "Tropical Trump" by some because of his nationalist agenda and anti-establishment tirades, his promise of a brutal crackdown on graft and crime has resonated with voters.
In a country which had a record 63,880 violent deaths in 2017. Bolsonaro has pledged to roll back gun controls and make it easier for police to kill.
With just three weeks until the runoff, Bolsonaro holds a commanding lead.
He won 46.3 per cent of valid ballots, far ahead of Haddad's 29 per cent, but short of the outright majority needed to avoid a second round, electoral authorities said.
With no backing from major parties and little funding, Bolsonaro relied on his skilful use of social media during the campaign.
He gained momentum after being stabbed at a rally one month ago, an incident that kept him from campaigning.
"This was a great victory, considering we had no television time, a party that is still very small with no campaign money and I was in hospital for 30 days," he said.
In his first public remarks, Bolsonaro pledged to slash the size of the state, reduce the cabinet to 15 ministries, cut payroll taxes and privatise or shut many state companies if he elected.
Supporters rallying outside his Rio de Janeiro home waved the Brazilian flag, chanting "Our president!" when he returned from voting, accompanied by a nurse, in a convoy of black cars.
Meanwhile, Haddad called on Brazilians to unite behind him, warning that the 1988 Constitution that underpinned Brazil's young democracy was under threat.
"There is a lot at risk in this election," Haddad told his supporters. "We want to unite all the democrats in Brazil."
Haddad portrayed a vote for him as a show of support for Workers Party founder and former President Luiz Inacio Lula da Silva, whom many voters associate with good economic times and falling inequality.
Lula was blocked from the race after being sentenced to 12 years in prison on corruption charges in one of the world's biggest-ever political graft scandals.