SÃO PAULO, Brazil — Brazil’s top electoral court ruled on Friday that former President Luiz Inácio Lula da Silva, who is serving a 12-year sentence for corruption, cannot run for a third term, eliminating the front-runner in a race many see as a struggle between democracy and due process.
Mr. da Silva, a two-time president who left office in 2011 with a record-high approval rating, has become a polarizing figure. Many supporters remain loyal to the metalworker who rose from the factory floor to the presidency and improved the lives of millions of the country’s poorest, giving him a wide lead in polls ahead of the Oct. 7 vote.
But he also has one of the highest rejection rates thanks to the Lava Jato, or Car Wash, investigation that landed Mr. da Silva in jail and revealed the political corruption that flourished during the 13 years that his party was in power.
In a poll published in August by the Datafolha research institution, Mr. da Silva easily led his rivals, with 39 percent of Brazilians saying they would vote for him, followed by a far-right former army captain, Jair Bolsonaro, who had the support of 19 percent of expected voters. His ouster blows open an already splintered race, just five weeks before the vote.
Like other political giants of the Latin American left, Mr. da Silva has failed to prepare a new generation of leaders. Barred from the race, he is expected to formally endorse his running mate, Fernando Haddad, a former mayor of São Paulo, as the Workers’ Party candidate.
But it is unclear if his support base, especially in the impoverished northeast, would shift its allegiance to Mr. Haddad, an economist, lawyer and university professor with little national recognition.
In simulations excluding Mr. da Silva, Mr. Bolsonaro takes the lead with 22 percent, followed by a former environmental minister, Marina Silva, with 16 percent. Mr. Haddad has been polling at just 4 percent.
In an extended special session of the electoral court that began on Friday and ended after midnight, a majority of the seven judges voted to bar Mr. da Silva from running again, and they ruled that his party had 10 days to replace him on the ballot.
The ruling was widely expected because of the corruption conviction, but the Workers’ Party had insisted on keeping Mr. da Silva, known as Lula, on the ballot, arguing that he was the victim of political persecution.
“When you prevent the most popular leader in the country from running for election, the risk for Brazilian democracy is very high,” the president of the party, Gleisi Hoffmann, warned in an interview before the decision.
Fernando Henrique Cardoso, Mr. da Silva’s predecessor, responded in an opinion article, saying that casting the country as a “democracy in ruins, in which the rule of law had given way to arbitrary measures” might be politically expedient for Mr. da Silva but was not true. The process that landed Mr. da Silva in prison shows the strength of Brazilian institutions, Mr. Cardoso argued.
“The legal proceedings in which he has been involved followed due process and have been carried out in accordance with the constitution and the rule of law,” Mr. Cardoso wrote.
Mr. da Silva was convicted of corruption and money laundering last year after he was accused of accepting a seaside condo remodeled to his liking as a bribe. An appellate court upheld the conviction in January and sentenced him to 12 years in prison. He was arrested in April after a dramatic standoff with the police while he was awaiting trial on other corruption charges.
Under the so-called Clean Slate law, put into effect in 2010 while Mr. da Silva was president, candidates are barred from running for office if a criminal conviction has been upheld on appeal.
Nonetheless, Mr. da Silva has maintained his innocence and support has poured in from leftist leaders around the globe, as well as the United Nations Human Rights Committee, which requested that the Brazilian government allow Mr. da Silva to exercise his political rights as a candidate.
The Workers’ Party registered his candidacy with the electoral court on Aug. 15. Mr. da Silva kept close tabs on his campaign from his prison cell in Curitiba, delivering handwritten instructions to his legal team, which includes Mr. Haddad.
The party argues that the ruling was rushed, coming just hours before the free television and radio campaign time kicks off. But rival candidates have pushed for a speedy decision so they can plan their campaign strategies.
“In this polarized moment, the best alternative for the good of Brazil is that the definitive makeup of presidential candidates be clarified quickly, transparently and with collegiality,” said Luís Roberto Barroso, the judge presiding over the case.