The once unthinkable risk that the far-right politician Jair Bolsonaro could become Brazil’s president is now real. The danger he poses to democracy is immense. The millions of Brazilians, particularly women, who have turned out to urge “not him” in mass protests know what is at stake. They are not merely anxious: they are, rightly, frightened. Yet his support has only increased in recent weeks. Polls put him around 10 points ahead of his nearest rival, Fernando Haddad of the Workers’ party (PT), in Sunday’s first round of voting, and suggest he could even win an expected runoff later this month.

To call him Latin America’s Donald Trump, as some have, is much too kind. Mr Bolsonaro is a misogynist and homophobe whose views on indigenous communities and the environment are every bit as grim. He praises torturers and the military dictatorship that ran Brazil from 1964 to 1985. He recently called for political opponents to be shot. His bigotry is portrayed as “honesty”.

It is true that he, like the US president, is a symptom of deeper problems. A congressman since 1991, he was previously seen as offensive but irrelevant. Now he has capitalised on the country’s woes with a populist campaign. Brazil is struggling to recover from its worst ever recession. The Operation Car Wash inquiry exposed the staggering breadth and depth of corruption. And the shocking rate of violent crime – Brazil saw a record 63,880 homicides last year – has increased the appeal of an iron fist. Being stabbed only boosted his campaign. He casts himself as an outsider who will clean up politics, has built support through social media, and does best among young voters. Yet he draws strength too from old Brazilian forces: the military, wealthy farmers and business people, the socially conservative; evangelical churches have thrown their weight behind him.

His rise has been powered by the real and perceived failings of the PT, thrown out of power in dubious circumstances two years ago with the impeachment of then president, Dilma Rousseff. The harsh austerity policies of her centre-right successor, Michel Temer, who avoided trial on corruption charges in a congressional vote last year, fuelled the anti-politics mood. Yet the PT’s towering figure, former president Luiz Inácio Lula da Silva, remains hugely popular even as he serves a 12-year sentence for corruption. Had the courts allowed Lula to stand, Mr Bolsonaro would have found this race much harder. Mr Haddad, the last-minute stand-in, is the former mayor of São Paulo but little known. Pleas for the centrist candidates Ciro Gomes, Geraldo Alckmin and Marina Silva to come together as a unifying alternative come much too late.

There are growing fears that Mr Bolsonaro could even win on the first round with an outright majority. Others worry that in a runoff defeated candidates – and voters who supported them – will fail to swing behind Mr Haddad in a decisive rejection of Mr Bolsonaro. His running mate, a general, recently suggested that in an anarchic situation the government could enact a self-coup. Opponents fear that if Mr Haddad wins, his rival will claim the result is illegitimate – and that the army could intervene.

Even the best-case scenario – a clear defeat for Mr Bolsonaro, accepted by his backers – would hardly be cause for celebration. The forces that gave rise to him will not vanish by themselves. Rebuilding the economy, curbing crime and tackling corruption will be essential to constructing a healthier political culture. That is a truly gargantuan task, yet it is now Brazil’s best hope.