BRASILIA — Right-wing Congressman Jair Bolsonaro took a commanding lead in Brazil's presidential election on Sunday, but the race headed for a second round of voting between him and leftist former Sao Paulo Mayor Fernando Haddad, according to exit polls and partial results.

With 92 percent of votes counted, Bolsonaro received 47 percent of valid ballots, far ahead of Haddad's 28 percent but short of the outright majority needed to avoid an Oct. 28 runoff.

Bolsonaro, a former army captain who has praised Brazil's 1964-1985 dictatorship and vowed a brutal crackdown on crime and graft, had surged in recent opinion polls on a wave of antipathy toward Haddad's Workers Party, whose leader is in prison after a corruption conviction.

Bolsonaro's rise 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 tip into its worst recession in decades.

Brazilian presidential candidate Jair Bolsonaro, of the far-right Social Liberal Party, flashes victory hand signs to supporters after voting in Rio de Janeiro on Sunday. Leo Correa / AP

Bolsonaro, 63, gained momentum after a near-fatal stabbing at a rally one month ago that kept him from campaigning.

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

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.

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

Haddad, a former education minister and one-term mayor of Sao Paulo, 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.

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.

In the most polarized election since the end of military rule in 1985, Bolsonaro is backed by a group of retired generals who have criticized the Workers Party governments and publicly advocate military intervention if corruption continues.

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.

Bolsonaro's running mate, a retired general, has said military intervention can be justified to restore civic order and that Brazil's Constitution can be torn up and rewritten without input from citizens.