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, as voters’ anger at corruption drove a major shift to the right in Latin America’s largest nation.

In what is likely to be a deeply polarizing 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 Oct. 28.

Dubbed a “Tropical Trump” by some pundits because of his nationalist agenda and anti-establishment tirades, 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 graft and crime have resonated with voters in the world’s fifth most populous country, which registered 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 percent of valid ballots, far ahead of Haddad’s 29 percent but short of the outright majority needed to avoid a second round, electoral authorities said.

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

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 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 mobilized.”

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.

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 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.

“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.

Slideshow ( 27 images )

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.

Slideshow ( 27 images )

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, though the same surveys underestimated the gap between the candidates on Sunday.

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 right-winger.

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

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, political analysts said that 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.

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 the 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.

GRAPHIC - Polling, issues and leading candidates in Brazil's election: tmsnrt.rs/2Ixe0NI