While Lula insists his only option lies in his own candidacy, his Workers’ Party, or PT, has a Plan B. In this scenario, the former mayor of São Paulo and current vice-presidential candidate Fernando Haddad would end up on the ballot if Lula’s protests, legal recourse and international campaign efforts prove futile. In case the ex-union leader is able to transfer enough of his votes to his replacement, he may win in a runoff election scheduled for Oct. 28. If the transfer doesn’t quite work out, however, and the PT is denied victory one way or another, the challenges for Brazil may be overwhelming.

An additional complication arises from the regional context in which this drama is being played out. In several Latin American nations, incumbents’ bans on opponents running for office have become a pattern. In Nicaragua in 2016, Daniel Ortega struck down or intimidated a sufficient numbers of rivals — especially the strongest one, Eduardo Montealegre — to finally win with 72 percent of the vote, virtually uncontested. In Venezuela this year, Nicolás Maduro made sure that the main opposition contenders, Henrique Capriles and Leopoldo López, were unable to run. Only a semi-sham candidate opposed Mr. Maduro.

In other countries, attempts at discouraging or prohibiting candidates from being on the ballot have also occurred. They range from the Mexican opposition leader Andrés Manuel López Obrador in 2005 ( he was finally elected in July) to several Guatemalan candidates barred by corruption charges, anti-nepotism clauses and human rights violations.

As in Brazil, many of these cases — not all, obviously — are tricky. Some contenders are disqualified for valid reasons, or at least lawful ones. Others are unquestionable victims of political persecution. It is hard to dispute the notion that Lula’s case tends to fall into the Venezuelan and Nicaraguan categories, rather than the others. Except that Brazilian democracy is not collapsing, demonstrators are not being murdered in the streets, students are not being jailed, and the media is not muzzled. As The Economist regretted a few months back, there may be government by judges in Brazil, but not a dictatorship.

In the end, though I believe that the Lava Jato scandal, as well as the diligence of judges like Mr. Moro, have served Brazil and Latin America well, I prefer to see Lula on the ballot than in jail.

The charges brought against him are too flimsy, the purported crime so petty (until now), the sentence so brazenly disproportionate and the stakes so high that in Latin America today, democracy should trump — so to speak — the rule of law. In an ideal world, the two go together and certainly do not clash with each other. In Brazil, they do. I’ll go with democracy, warts and all.

Jorge G. Castañeda, foreign minister of Mexico from 2000 to 2003, is a professor at New York University and a contributing opinion writer.

Follow The New York Times Opinion section on Facebook and Twitter (@NYTopinion), and sign up for the Opinion Today newsletter.