By Anthony Boadle and Mateus Maia
BRASILIA (Reuters) - Far-right Congressman and former Army captain Jair Bolsonaro won nearly half the votes in Brazil's first-round presidential election on Sunday, marking a major shift to the right in Latin America's largest nation fuelled by voters' anger at corruption.
In what is likely to be a deeply polarizing race, Bolsonaro, who has praised Brazil's 1964-1985 military dictatorship, will face leftist Fernando Haddad, the former mayor of Sao Paulo, in a second round of voting on Oct. 28.
Bolsonaro won 46.3 percent of valid ballots, far ahead of Haddad's 29 percent but short of the outright majority needed to avoid an runoff, electoral authorities said.
Bolsonaro, 63, had surged in recent opinion polls on a wave of antipathy towards Haddad's Workers Party, whose leader is serving 12 years in prison after a corruption conviction.
Bolsonaro, who has vowed a brutal crackdown on crime and graft, gained momentum after a near-fatal stabbing at a rally one month ago that kept him from campaigning.
Some pundits have dubbed Bolsonaro a "Tropical Trump" because of his large social media following, pugnacious demeanour and multiple wives. He faces federal hate crime charges for racist and misogynist rants.
His commanding lead heading into the second round marks another advance by populist, anti-establishment leaders, who have won power in eastern Europe, the United States and the Philippines.
In his first public remarks celebrating his lead in the vote, 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.
In video streamed live over social media with economic advisor Paulo Guedes sitting by his side, Bolsonaro said he would have clinched the race with a majority of votes on Sunday if it were not for faulty voting machines. He provided no details.
Bolsonaro's 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 the leftist 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.
"Bolsonaro is an example of honesty. Our country needs someone to take tough measures," said civil servant Orlando Senna, who said his uncle served in the army with Bolsonaro.
Senna said he was worried that Bolsonaro's presidential rivals would gang up on him and back Haddad in the runoff.
In Sao Paulo, supporters celebrated on a main avenue with a giant inflatable doll in military uniform depicting Bolsonaro's running mate, retired general Hamilton Mourão.
In the most polarized election since the end of military rule in 1985, Bolsonaro is backed by a group of retired officers like Mourão who have criticized Workers Party governments and publicly advocate military intervention if corruption continues.
THREAT TO DEMOCRACY
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 Bolsonaro in the second round.
Haddad called on Brazilians to unite behind him, warning that the 1988 Constitution that underpinned Brazil's young democracy was at risk. He said he had already spoken to three other candidates to join forces against the right-winger.
Haddad, a former education minister, had 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.
However, preliminary results showed unexpectedly big congressional wins by Bolsonaro proxies including former military police Major Olimpio Gomes, his campaign manager in Sao Paulo, who was elected to Senate.
That and upset victories in the Rio de Janeiro and Minas Gerais governor races underscored a wave of enthusiasm for Bolsonaro's allies and a backlash against the political establishment.
The rivals will have to move to the centre now to win more votes in the runoff, said Maurício Santoro, professor at Rio de Janeiro state university.
"Haddad will have to distance himself from Lula and quickly pick a market-friendly finance minister. Bolsonaro will have to set aside his hate speeches and straighten out contradictions between his aides," Santoro said.
By highlighting his ties to Lula, Haddad also played into the hands of Bolsonaro, who is riding a wave of anger at the Workers Party, which his supporters blame for widespread corruption, rising crime and recession.
Bolsonaro has promised to reverse a crime wave that brought a record 63,880 deaths in 2017, the most of any country in the world, by rolling back gun controls and making it easier for police to kill.
GRAPHIC - Polling, issues and leading candidates in Brazil's election: https://tmsnrt.rs/2Ixe0NI
(Reporting by Anthony Boadle and Mateus Maia in BrasiliaAdditional reporting by Brad Haynes and Brad Brooks in Sao Paulo; Editing by Daniel Flynn and Cynthia Osterman)