BRAZIL’S supreme court was damned whatever it did. On April 4th, after 11 hours of debate, it rejected by six votes to five a plea by lawyers for Luiz Inácio Lula da Silva, the country’s former president, that their client should not be sent to prison following his conviction last year for corruption until he has exhausted all possible appeals.

That decision will be seen by his supporters as endorsing a political vendetta, potentially damaging the legitimacy of a presidential election in October. Lula leads in the opinion polls, by a wide margin. But upholding Lula’s request would have had big negatives, too. It would have reversed the court’s own doctrine, established by the same narrow margin just two years ago, that the guilty can be jailed after their sentence is confirmed on first appeal. And, according to many prosecutors and judges, it would have sucked the life out of the four-year anti-corruption probe known as Lava Jato (Car Wash).

Lava Jato has revealed massive graft in business and politics, not just in Brazil but across much of Latin America. Its revelations have taken a toll on the credibility of democratic politics. But it has held out hope that by punishing the powerful, ending impunity for stealing public money and forcing reform of campaign finance it will ultimately cleanse and strengthen the region’s democracies and economies.

The case of Lula, Brazil’s president from 2003 to 2010, is emblematic. Prosecutors found that during the governments of his Workers’ Party (PT) construction companies systematically overpaid for public contracts, with money going into the pockets of public officials and coalition allies, and into party coffers. They claim not only that Lula knew about all of this but that he interfered to arrange specific contracts. Their evidence comes from testimony extracted in plea bargains.

Lula faces nine separate charges of corruption or influence peddling, all of which he denies. He was convicted on the first charge—that he received a beachside flat in return for facilitating a contract after his presidency had ended—by Sérgio Moro, a crusading young judge. In January that conviction was upheld by a regional appeal court, and his sentence increased from nine years in jail to 12.

For its critics, Lava Jato has begotten a Robespierrean tyranny of prosecutors and judges. Many convictions result from generous plea-bargain deals offered to suspects. Marcelo Odebrecht, who admitted that his construction firm paid bribes of almost $1bn in a dozen countries, received only a ten-year sentence, a quarter of which was served in jail. He is now incarcerated in the exacting gulag of his São Paulo mansion.

Defendants claim that judges have too much discretion. Lula’s lawyers say that Mr Moro did not show that the flat, which Lula never occupied or owned, was a quid pro quo for any action. Mr Moro followed the supreme court in a previous corruption case involving the PT, known as the mensalão, in applying the doctrine of command responsibility (used in the Nuremburg trials). It was enough that contracts were overpriced, that Lula was close to construction bosses and that he was the PT’s unquestioned leader.

Right now, the long jail stretch, which could start any day, looks disproportionate. That matters in part because Lula continues to be revered by poorer Brazilians for the social programmes he implemented in a country where inequality and neglect of the poor was long the norm. He was unlikely to have been able to run in the election in any event: a separate law bars candidates who have been convicted of corruption by an appeal court. But his entering a prison cell will still be momentous for Brazilian democracy. It was not reassuring that the army chief appeared to try to influence the court against Lula by tweeting this week that his institution “repudiates impunity”.

Still, many Brazilians are pleased by the ruling, and not only because they think the PT tried to place itself above the law. There are broader implications. Brazil is rare in allowing two levels of appeal (three in some cases). Without the prospect of jail, suspects would seek to spin out legal cases until they lapse rather than offer evidence.

Whatever its flaws and risks, the anti-corruption drive marks an advance. If judges are taking such momentous decisions, it is partly because the politicians have flunked them, from regulating appeals to political reform. Without plea-bargaining, and with the narrow and formalistic approach to corruption adopted before the mensalão, taxpayers were ripped off and voters duped. At least that should be harder from now on.