Laura Carvalho, an economist at University of São Paulo, said the best bet for the Workers’ Party’s candidate would be to focus on pocketbook issues over the next three weeks. “Instead of focusing on racism and misogyny, which did not have much effect, they should focus on the economic agenda and the anti-worker aspect of the Bolsonaro candidacy,” Ms. Carvalho said.

While several of Brazil’s neighbors have steered to the right politically in recent years, a victory by Mr. Bolsonaro, a populist conservative who stands to join a growing roster of anti-establishment leaders around the world, would be a seismic conservative shift.

Critics of Mr. Bolsonaro and political analysts have watched his rise with alarm, fearing he could become an authoritarian leader in the mold of Recep Tayyip Erdogan of Turkey and Rodrigo Duterte of the Philippines.

Before running for president, Mr. Bolsonaro, a former Army captain with little to show for his seven terms in Congress, faced federal hate speech charges for homophobic, misogynist and racist comments. He also spoke with admiration and nostalgia for Brazil’s military dictatorship, during which 434 people were killed or disappeared and thousands were tortured from 1964 to 1985.

Rejected by mainstream parties, Mr. Bolsonaro struggled to find a running mate until early August, when he picked a recently retired general who has advocated military intervention as a means to purge a corrupt ruling elite. He has said he intends to appoint other military leaders to central roles.

Mr. Bolsonaro’s first-round victory was all the more remarkable because he lacked the backing of a major party and campaigned on a shoestring budget, relying mainly on social media to build a base. As of mid-September, the Bolsonaro campaign reported having spent about $235,000, a small fraction of the $6.3 million the Haddad campaign disclosed having spent.

Mr. Bolsonaro’s rise was enabled by the political divisions that have torn the country apart in recent years.