Brazil's far-right presidential candidate Jair Bolsonaro has said he is already in talks with other politicians in congress to gain support if he wins a second-round run-off later this month, as his party would not be able to govern alone.

Speaking the day after he came just shy of a first-round victory in Brazil's most polarised election in decades, Mr Bolsonaro also said he would stick with his Wall Street-friendly economic advisor Paulo Guedes, adding that he would hew to his hard line message and not become a "peace and love" candidate.

The former army captain won nearly half the votes in Brazil's first-round presidential election.

It came as voters' anger at corruption drove a major shift to the right in Latin America's largest nation.

Mr 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 28 October.

Dubbed a "Tropical Trump" by some pundits because of his nationalist agenda and anti-establishment tirades, Mr Bolsonaro was swept from the political margins this year by a wave of antipathy toward scandal-plagued traditional parties.

His promise of a brutal crackdown on corruption and crime have resonated with voters in the world's fifth most populous country, which registered a record 63,880 violent deaths in 2017.

Mr Bolsonaro has pledged to roll back gun controls and make it easier for police to kill.

With just three weeks until the runoff, Mr Bolsonaro holds a commanding lead.

He won 46.3% of valid ballots, far ahead of Mr Haddad's 29%, but short of the outright majority needed to avoid a second round, electoral authorities said.

In a seismic shift in Brazilian politics, Mr Bolsonaro's once-tiny Social Liberal Party (PSL) was poised to become the second-largest force in Congress after legislative elections also held yesterday, giving a boost to his agenda of slashing taxes and state involvement in the economy.

With no backing from major parties and little funding, Mr Bolsonaro relied on his skilful use of social media during the campaign.

He gained momentum after a near-fatal stabbing at a rally one month ago 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 video streamed live over social media.

"We have to believe in our Brazil. We have to remain mobilised."

In his first public remarks, Mr 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 is elected.

His surge in opinion polls prompted a rally in recent days in Brazil's currency and stock market.

Many investors want to avoid a return of Haddad's Workers Party after the end of its 2003-2016 rule saw the world's eighth-largest economy fall into its worst recession in decades.

Supporters rallying outside his Rio de Janeiro home waved the green-and-yellow national flag, chanting "Our president!" when he returned from voting, accompanied by a nurse, in a convoy of black SUVs.

In Sao Paulo, supporters celebrated on a main avenue with a giant inflatable doll in military uniform depicting Mr Bolsonaro's running mate, retired general Hamilton Mouro.

In the most polarised election since the end of military rule in 1985, Mr Bolsonaro is backed by a group of retired officers such as Mr Mouro, who have criticised Workers Party governments and publicly advocate military intervention if corruption continues.

Mr Haddad's campaign headquarters in a Sao Paulo hotel broke out in cheers when exit polls showed that the race would go to a runoff.

Some recent polls have projected he could beat Mr Bolsonaro in the second round, though the same surveys underestimated the gap between the candidates yesterday.

Mr Haddad called on Brazilians to unite behind him, warning that the 1988 Constitution that underpinned Brazil's young democracy was under threat.

He said he had already spoken to three other candidates to join forces against the Mr Bolsonaro.

"There is a lot at risk in this election," Mr Haddad told his supporters. "We want to unite all the democrats in Brazil."