Sao Paulo, Nov 8 - Brazil's Supreme Court delivered a ruling that could release almost 5,000 inmates still appealing their convictions, including former President Luiz Inácio Lula da Silva and other powerful figures jailed in a sprawling corruption investigation.

The court decided in a 6-5 vote late Thursday that a person can be imprisoned only after all appeals to higher courts have been exhausted.

The decision appears to cover Da Silva, whose attorneys said they will request his release Friday.

That move will initially depend on a judge based in the southern city of Curitiba, where the former president is jailed.

The ruling also covers others convicted in cases arising from the so-called Car Wash investigation, which has ensnared dozens of top politicians and business leaders in Latin America's largest nation. They will now be able to seek release.

Prosecutors from the Car Wash probe said in a statement the top court's decision "goes against the sentiment of repudiating impunity and the fight against corruption."

Supporters of Da Silva celebrated the ruling, holding up signs saying "Lula," the name by which the president who governed from 2003 to 2010 is universally known here.

The Supreme Court's debate began in mid-October and its result could throw Brazil's political landscape into uncertainty.

Da Silva had been favoured to win the 2018 presidential election, but his conviction prohibited him from running.

He remains a popular figure on the left, whose politicians and voters have ceaselessly called for his release.

The decision marks a sharp change for Brazil's top court, which in February 2016 accepted that defendants whose convictions are upheld may be jailed even if their other appeals are pending.

Brazil's constitution states that no one can be considered guilty until due process is concluded.

"I'm not surprised, politicians rarely stay very long in jail," said Rivaldo Santos, a 43-year-old waiter in Sao Paulo. Da Silva "spent some time (in jail), which is a change, but not nearly as much as other people that committed crimes but didn't have judges and lawyers on their side."

Da Silva presided over a period of rapid economic growth fuelled by a commodities boom that expanded the country's middle class.

His huge Bolsa Familia welfare program helped lift millions from poverty, and he left office with an approval rating above 80 per cent.

The former union leader is widely referred to as a "political animal" whose impassioned oratory can just as easily elicit laughter or tears from those among his supporters.

Justice Gilmar Mendes, who voted for the release of inmates who have yet to conclude their appeals, said Da Silva's case "contaminated" debate on the case.

"That was not good at all for rational debate," Mendes, an open critic of the Car Wash probe.

Da Silva's hand-picked successor, Dilma Rousseff, was impeached and removed from office in 2016. Then Da Silva was jailed in April 2018 after a group of judges upheld his conviction for corruption and money laundering. That left his leftist Workers' Party rudderless, and it was further demoralised when routed in the 2018 general elections.

Da Silva is still appealing a case related to the alleged purchase of a beachfront apartment in the city of Guaruja, in Sao Paulo state.

He was also sentenced by a lower court judge in a case regarding alleged ownership of a farmhouse in Atibaia, outside Sao Paulo.

The 74-year-old politician has denied any wrongdoing in those cases. He accuses then-judge Sergio Moro and Car Wash prosecutors of political persecution.

Left-leaning supporters hailed the decision that could free their standard-bearer, but want more.

They hope Da Silva's sentence is annulled later this month in another Supreme Court debate over whether Moro was unbiased when he delivered his rulings.

Meantime, his conviction continues to bar him from running for office.

"Lula is not electable, but that is not needed for him to take center stage," political analyst Alberto Almeida said.

"He can draw more politicians from the center and end up as a dealmaker for his party's candidate in the 2022 presidential elections."

Right-leaning Brazilians have used social media in recent weeks to attack justices who cast votes that could allow Da Silva to walk out of his cell.

A protest previously scheduled for this weekend is aimed at showing support for Moro, now serving as President Jair Bolsonaro's justice minister, and his crusade to root out corruption.

Attacks on the Supreme Court's ruling will doubtless feature loudly, with the prospect of Da Silva's release already looming.

"I will pick you up tomorrow! Wait for me," Da Silva's girlfriend wrote on Twitter.

In addition to the former president, at least 4,895 prisoners stand to benefit from the decision, Brazil's justice council estimates.

Most analysts say the decision will not benefit violent criminals. Justice Alexandre de Moraes said those convicts will remain behind bars because judges already issued preventive detentions in their cases, meaning a sentence is not required to jail them.

Brazil's national association of public prosecutors, though, insists the release of dangerous criminals is a possibility.

"I ask God for there to be peace on the streets and protection of our democracy," Antônio Costa, head of nonprofit organisation Rio de Paz, wrote on Twitter.