RIO DE JANEIRO (AP) — A sharply divided top court voted early Thursday to reject an attempt by former Brazilian President Luiz Inacio da Silva to stay out of jail while he appeals a corruption conviction, delivering a hard blow to the front-running candidate in this year's presidential election in Latin America's largest nation.

After nearly 11 hours of often heated debate, the Supreme Federal Tribunal voted 6-5 to deny da Silva's request to stave off a 12-year prison sentence while he fights a conviction that he has always argued was nothing more than a ploy to keep him off of the October ballot.

Despite the conviction and several other corruption charges against him, da Silva leads all preference polls for the election.

The decision means that da Silva will likely be jailed soon, though probably not until at least next week thanks to various technicalities.

Chief Justice Carmen Lucia, who was sharply criticized during the session by various colleagues, cast the deciding vote after the court was tied at 5 to 5.

"The constitution secures individual rights, which are fundamental to democracy, but it also assures the exercise of criminal law," she said.

The debate at the Supreme Federal Tribunal underscored how fraught the matter is at a time of high tension and angst in Brazil.

Justice Gilmar Mendes, traditionally a critic of da Silva, voted in favor of da Silva's petition to stay out of jail, challenging his colleagues to buck pressure from society.

"If a court bows (to pressure), it might as well not exist," said Mendes.

Justice Luis Roberto Barroso argued that the integrity of the justice system was at stake.

"A penal system that doesn't work with minimal effectiveness leads to an instinct for taking justice into one's own hands," Barroso said in voting against da Silva.

Justice Rosa Weber, who legal analysts had said could be key because there was much doubt about her position on the matter, voted against da Silva.

In one of several brisk exchanges, after Weber's vote, justice Marco Aurelio Mello accused Lucia of plotting against da Silva's case. Mello said limiting the vote just to the habeas corpus petition and not the larger question of when a convicted person should be forced to begin serving a sentence helped sway Weber's vote.

"I want this to be registered in the court's records," Mello told Lucia, who responded by saying "yes" to the request.

The session reflected the debate happening across Brazil as millions tuned into the televised session. When the decision was delivered, fireworks and yells could be heard and seen in Rio de Janeiro and Sao Paulo, two of the nation's most important cities.

On the eve of the session that began Wednesday afternoon, the country's army commander raised eyebrows — and was widely celebrated and condemned online — with tweets subtly supporting da Silva's incarceration.

Gen. Eduardo Villas Boas posted two tweets Tuesday night that many interpreted as a form of pressure on the 11 justices on the Supreme Federal Tribunal and a veiled threat of intervention. Such concerns are taken seriously in a country that experienced a 1964-1985 military dictatorship.

"In Brazil's current situation, it's worth asking our institutions and the people who is really thinking about what is best for the country and future generations, and who is only worried about their personal interests?" the general wrote in one tweet.

In a second tweet, Boas wrote that he shared people's anxiousness and "repudiated impunity."

O Globo, one of the country's leading newspapers, criticized the comments, saying in an editorial that a military chief should "not be opining over judicial and political questions."

In a statement to O Globo, Gen. Joaquim Silva e Luna, the defense minister, said Boas' intention was to assure people that force would not be used.

Da Silva, who was once wildly popular after his two terms as president from 2003 to 2010, has become a polarizing figure amid a massive corruption scandal that has roiled Brazil the last several years and made average citizens furious with the political class.

Da Silva was convicted last year of helping a construction company get sweetheart contracts in exchange for the promise of a beachfront apartment. The conviction was handed down by Judge Sergio Moro, who is presiding over cases involving the mammoth "Car Wash" investigation.

The former president suffered another blow in January, when an appeals court upheld the conviction. The three reviewing magistrates even lengthened the sentence to 12 years and one month.

While da Silva, known simply as "Lula" to Brazilians, has further appeals available, he could be forced under Brazilian law to begin serving his sentence, which Moro and the other judges have ordered.

Da Silva's lawyers argued their client has a constitutional right to stay out of jail until all appeals are exhausted.

In an unrelated case in 2016, the Supreme Federal Tribunal disagreed with that logic, ruling that a convict could start serving a sentence after a first appeal was denied.

Throughout all the legal battles, da Silva has been campaigning nationwide, criticizing detractors and promising not to give up. Last week, while campaigning in the southern state of Parana, where Moro convicted him, two buses in his caravan where hit with bullets. Nobody was hurt.

___

Peter Prengaman on Twitter: twitter.com/peterprengaman

Mauricio Savarese on Twitter: twitter.com/MSavarese