A STEEP hill and a concrete wall divide the worlds of Gabriela Moura, a student from Paraisópolis, a favela in the city of São Paulo, and Roberto Inglese, a lawyer from the prosperous neighbourhood of Morumbi. But on October 7th the two paulistanos were united in their choice for Brazil’s president: Jair Bolsonaro, a far-right former army captain. “All the other politicians are corrupt,” said Mr Inglese, who drove his SUV to vote at a private Italian school. “We need someone with a strong fist against crime,” said Ms Moura, who feared walking to a government-run day-care centre to vote because she had recently been assaulted nearby.

Such sentiments have brought Mr Bolsonaro to the verge of victory in a run-off, to be held on October 28th. He won 46% of the vote in the first round amid a crowded field of candidates. His rival, Fernando Haddad of the left-wing Workers’ Party (PT), enters the second round 17 percentage points behind. Betting markets now give Mr Bolsonaro an 83% chance of becoming Brazil’s next president.

That would be an extraordinary response to a series of traumas that have befallen Latin America’s biggest country over the past several years: the deepest and longest economic recession in the country’s history; a corruption scandal, called “Lava Jato” (“Car Wash”), that implicated all major political parties; and rising rates of violent crime. The number of murders in Brazil reached a record of nearly 64,000 last year. To fix these problems Brazilians are turning to a politician-provocateur more notable for the extremism of his rhetoric than for anything he achieved in seven terms as a congressman. Mr Bolsonaro has offended various groups, including women and gays; encourages police to kill criminals; and regards the dictators of the 1970s and 1980s as role models.

Most analysts had thought that the right-winger would eventually lose to someone less divisive, at least in the second round of voting. Geraldo Alckmin, the nominee of the Party of Brazilian Social Democracy (PSDB), had assembled a vast coalition of centrist parties, which gave him 40 times more free television advertising time than Mr Bolsonaro had. In past elections, that would have been decisive. However, Mr Bolsonaro’s candidacy, like that of Donald Trump in America, was promoted mainly by social media and by the news coverage he attracted.

Two events crystallised support for him in September. The first was the disqualification on August 31st of Luiz Inácio Lula da Silva, a former president who is serving a jail sentence for corruption, as the PT’s nominee for president. Lula and the PT are popular among some Brazilians, especially the poor. But the recession and revelations of scandal occurred under a PT president, Dilma Rousseff, who was impeached in 2016 (for a violation of budget-accounting laws). Mr Haddad rose rapidly in the polls after he replaced Lula as the PT’s candidate. Fearing a PT victory, voters who despise the party cast a “tactical vote” for Mr Bolsonaro, the only candidate ahead of Mr Haddad, says Mauro Paulino of Datafolha, a pollster.

A knife attack on Mr Bolsonaro at a campaign rally on September 6th, which put him in hospital for the final month of the campaign, also boosted his candidacy. It produced a sympathy vote and made it harder for rivals to criticise him. As he and Mr Haddad pulled away from the rest of the field, “the decision of voters became about whom you hate the most,” says Thiago de Aragão of Arko Advice, a consultancy. For the largest group of first-round voters, that was the PT.

Mr Bolsonaro’s success extended to congress, which will be the most conservative since the end of dictatorship in 1985. The re-election rate to the lower house fell from 56% to 47% as voters rejected candidates from parties tainted by the Lava Jato scandal. Although Mr Bolsonaro had almost no coalition allies in the first round, candidates sympathetic to him did surprisingly well in the one-round congressional election. His own Social Liberal Party, until now a tiny group, will have 52 seats in the 513-member lower house, up from eight in the outgoing congress. That will make it the second-biggest in the chamber (after the PT). Mr Bolsonaro will be able to count on support from other parties. Conservative politicians representing rural districts share his fondness for guns and his disdain for restrictive environmental rules. Some parties of the centre, including Mr Alckmin’s PSDB and the Brazilian Democratic Movement of the current president, Michel Temer, saw their support collapse. If Mr Bolsonaro wins they are unlikely to put up much of a fight against him.

He may thus be able to fashion a governing majority from the new legislature. This makes it less likely than many analysts had thought that a Bolsonaro presidency would face a crisis of governance. In turn, that might reduce the danger of a direct attack on democracy, for example through “self-coup”, ie, a Bolsonaro-led intervention by the army. His running-mate, Hamilton Mourão, has suggested such a possibility in case of “anarchy”. But congressional co-operation might help Mr Bolsonaro subvert democratic institutions and norms in other ways, such as encouraging police brutality. He may have enough allies to enact such measures as loosening gun control and rolling back environmental legislation.

What is less clear is whether he will have the votes to pass contentious economic reforms, such as reducing pension spending and privatising state-owned companies. Some of these require constitutional amendments. Although financial markets are betting that Mr Bolsonaro, if elected, will be able to reduce Brazil’s budget deficit and its debt burden, “it’s not clear that the support Bolsonaro is building extends to painful measures to cut spending,” according to Capital Economics, a research firm.

To snatch the presidency from him Mr Haddad, a former mayor of São Paulo and education minister, will have to placate voters who are disenchanted with the PT while retaining its core supporters. That will not be easy. At the most recent televised presidential debate on October 4th, Mr Haddad responded to a rival candidate’s request for “self-criticism” by praising the PT’s social programmes. The studio audience groaned. Campaign ads that declare “Haddad is Lula” may impress millions of Brazilians who stopped being poor under Lula’s government; they suggest to others that he would be Lula’s puppet.

To have a chance of winning, Mr Haddad will have to move toward the political centre. It will help that he is more moderate than many of the most influential figures in the PT, who are much further to the left. Another advantage Mr Haddad has is a slightly lower rejection rate than Mr Bolsonaro’s: 36% of Brazilians would not vote for Mr Haddad under any circumstances, according to IBOPE, a polling firm. For Mr Bolsonaro, the figure is 43%. Rather than merely bashing Mr Bolsonaro for his bigotry and authoritarianism, argues Esther Solano, a sociologist at the Federal University of São Paulo, Mr Haddad must now present pragmatic ideas for bolstering the economy, curbing corruption and reducing crime. Mr Bolsonaro can win “if he stays quiet”, says Mr Aragão. To have a chance, Mr Haddad must speak loudly and clearly in his own voice.