RIO DE JANEIRO — An ultra-right-wing populist is poised to assume the presidency of the world’s fourth-largest democracy. Jair Bolsonaro, a former army captain, won more than 46 percent of the vote during the first round of Brazil’s presidential election on Sunday. He will face the runner-up, Fernando Haddad of the Workers’ Party in a runoff on Oct. 28. Mr. Haddad secured just 27 percent of the vote. Even if all other leftist and centrist candidates endorse him, he will struggle to stop Mr. Bolsonaro’s ascent.

Brazilians are frustrated, disillusioned and angry. Well before Mr. Bolsonaro’s rise, they were protesting against cynical politics, spiraling corruption, economic stagnation and breathtaking levels of crime. Although recent polls suggest that most Brazilians support democracy, they are more disunited than ever. More than half admit that they would “go along” with a nondemocratic government if it “solved problems.” (Mr. Bolsonaro is among them. He is also on record saying he would not accept the outcome of an election where he is not declared the winner.)

Brazil’s democracy is teetering on the edge, but its collapse is not inevitable. Its rejuvenation will demand foresight, humility, tolerance and the courage to confront what appear to be insurmountable differences. No matter who wins the second round, the coming weeks and months will see polarization deepening and the tide of hatred rising. This does not make the pursuit of a progressive middle ground and real solutions to Brazil’s problems any less important.

The election underlines the scale of Brazil’s divisive politics. The country’s political polarization is deeply personal, cutting across age, gender and class. Many friends and family members are openly wondering whether their parents, siblings or colleagues who supported Mr. Bolsonaro were always closet authoritarians. And those who did not support him are visibly nervous, fearful of the violent resentment that his campaign unleashed.

Mr. Bolsonaro’s success owes much to his power to divide. Many of his core followers — especially the young men who make up his base — are committed to his corruption-busting and communist-combating crusade. Others, including middle-class women, are attracted more narrowly to his “tough on crime” message. And some of the country’s business elite see in Mr. Bolsonaro — along with his running mate, the retired army general Antonio Hamilton Mourão, and his pro-market financial adviser, Paulo Guedes — a bulwark against the return of the left-wing Workers’ Party and its jailed leader, former President Luiz Inácio Lula da Silva.

Brazil’s three major political parties share the blame for the country’s fragmentation. Both Mr. Lula and his successor, Dilma Rousseff, regularly invoked “us versus them” rhetoric during their 13 years in power, especially when faced with mounting corruption scandals unearthed by the “Carwash” investigations. The other two main parties — P.M.D.B. and P.S.D.B. — also set Brazil on a collision course when they voted to unseat Ms. Rousseff in August 2016. Described by Ms. Rousseff’s supporters as an illegal coup, the impeachment further divided Brazilians.

Yet it is Mr. Bolsonaro that represents the greatest existential threat to Brazil’s democracy. He has gleefully promised to drain the swamp in the capital, Brasília, and to violently restore law and order. But Brazilians should take a close look at his record as the second round approaches: After serving seven terms across almost three decades, first as a City Council member and then as a congressman, he delivered just two bills. While he clearly has the credentials to lead an authoritarian backlash, many doubt that he has the skills to govern in a multiparty environment that depends on coalition building.

Mr. Bolsonaro and his running mate are proud apologists for the military dictatorship that reigned from 1964 to 1985. He once said that its only shortcoming was that it had not killed more people. His team also supports violently repressing crime: He openly supports expanding police powers to use lethal force, reducing the age of penal responsibility from 18 to 16, and bringing back the death penalty. He advocates for greater religious involvement in public life. Last year, he declared that Brazil is a Christian country; that there is no such thing as a secular state; and that those who disagree should leave or bow to the majority. He has received repeated denunciations from the attorney general for propagating hate speech, and is openly hostile toward Afro-Brazilian communities, indigenous populations and members of landless movements, whom he has described as terrorists.

Brazilians can embrace the politics of division and the seductive appeal of simplistic solutions, following the path of populist authoritarians in Hungary, Poland and the Philippines. Alternatively, they can preserve and renew their young democracy.

To start, they will need to build a popular front to contain and defeat Mr. Bolsonaro and his hard-liners in the short term. This will be no easy task: His party now has 52 seats in Congress compared with just eight before the election. Moreover, Mr. Bolsonaro will almost certainly double down on many citizens’ deep antipathy toward the Workers’ Party and its involvement in corruption. His opponent, Mr. Haddad, will struggle to build a coalition, particularly with many P.S.D.B. voters likely to back Mr. Bolsonaro.

The decisive question will be whether Brazilians fear Mr. Bolsonaro’s anti-democratic message more than they hate the Workers Party. While it is difficult to predict what comes next, one thing is certain: Brazilians are facing the most important struggle of their generation.

But that is just in the short term. If Brazilians are to genuinely restore their democracy, they will need to do much more than just vote to keep Mr. Bolsonaro from office. At a minimum, they must build inclusive political parties, invest in a new generation of young leaders and construct bridges based on empathy, understanding and respect. If they fail to do so, the ground will continue to be fertile for authoritarians like Mr. Bolsonaro.

Robert Muggah is the co-founder of the Igarapé Institute, a think tank based in Rio de Janeiro. This was written in his personal capacity.