LESS than two years ago, Brazil’s municipal elections seemed to give a clear message. The vote came barely a month after Dilma Rousseff, the president, was impeached for fiscal misdemeanours, ending more than 13 years of rule by the left-of-centre Workers’ Party (PT). Brazilians gave the PT a hammering: the party won only 254 mayoralties out of more than 5,500, down from 638. The centre-right Party of Brazilian Social Democracy (PSDB) did well, winning 803. Everything suggested that the PSDB, which governed Brazil successfully in 1995-2002, would win this year’s presidential election.

With just a month to go before the election, the country’s politics have been turned upside down. The PSDB’s candidate, Geraldo Alckmin, languishes at about 7% in the opinion polls. Luiz Inácio Lula da Silva, the PT’s leader and Ms Rousseff’s mentor, commands around 37% and a widening lead, despite having begun a jail sentence for receiving a beachside flat from a construction firm that benefited from padded government contracts. The electoral tribunal confirmed on August 31st that he cannot run for office, since his conviction was upheld on appeal. Lula’s task now is to persuade his supporters to vote for Fernando Haddad, the PT’s vice-presidential nominee and a former mayor of São Paulo.

Second in the polls, with around 19%, is Jair Bolsonaro, a former army captain of extreme right-wing views. Despite having been a backbench congressman for 27 years, Mr Bolsonaro is a fan of Brazil’s military dictatorship of 1964-85; his running mate is a retired general who last year mused that the armed forces might have to step in to settle the country’s problems.

Much can change in the next month. But there is a real chance that the inevitable run-off will be between Mr Haddad and Mr Bolsonaro. By rights, neither should have a chance. The PT’s policy mistakes led Brazil into a deep and avoidable recession in 2015-16. On its watch, a handful of big companies engaged in wholesale bribery and corruption, exposed in an investigation known as Lava Jato (“Car Wash”). As for Mr Bolsonaro, he defends a repressive regime which bequeathed an economic lost decade in the 1980s and a country in which 40% of 7- to 14-year-olds were not at school.

What explains the electorate’s apparent amnesia? The starting point is public anger over the combination of the country’s worst-ever recession, a concomitant collapse in public services (dramatised by this week’s fire at the National Museum) and the widespread corruption revealed by Lava Jato, which went far beyond the PT.

Ms Rousseff’s impeachment brought to power Michel Temer, her vice-president from a coalition partner which broke with the PT in early 2016. A veteran dealmaker of the amorphous political centre, Mr Temer pushed through unpopular but essential economic reforms, including a cap on public spending. But his credibility was destroyed when he was taped apparently discussing bribes with a businessman. He twice used his support in congress to assert his immunity from prosecution.

It is Mr Temer’s performance that has facilitated the revival of Lula and the PT. It has allowed them to rail against “neo-liberalism”, even though austerity is the result of Ms Rousseff’s irresponsibility. Many poorer Brazilians recall rising prosperity and government aid under Lula’s presidencies. Writing in the New York Times, Lula falsely stated that his jailing “has nothing to do with corruption” and is “for political reasons”, but rightly said that “millions of Brazilians” believe this.

The PSDB is tarnished too. It joined Mr Temer’s government. It failed to expel Aécio Neves, its presidential candidate in 2014, who faces charges of corruption. The middle class—the core of the PSDB’s base—is in an angry mood. That showed up in the street protests calling for Ms Rousseff’s impeachment. The PSDB failed to channel the rage or articulate a clear political alternative. Many protesters seem to have turned to Mr Bolsonaro, who campaigns as the PT’s nemesis.

An extraordinary campaign may yet hold further twists. Mr Alckmin, though unexciting, has built a broad political alliance that gives him the lion’s share of the free television advertising that began this week. A fourth candidate, Marina Silva, an evangelical Protestant (like Mr Bolsonaro) and a former environment minister in Lula’s governments, won 21% of the vote in 2014. Having refused to ally with traditional parties, she has few resources, but could yet capture some Lula voters unpersuaded by Mr Haddad. Unless either Mr Alckmin or Ms Silva takes off, Brazilians will have let their justified anger over corruption blind them to other, arguably bigger, failings.