Brazil's top court has voted to overturn a rule about the jailing of criminals – a change which could lead to ex-President Luiz Inácio Lula da Silva being freed from custody.

The ruling, announced on Thursday, stipulates that convicted criminals should go to prison only after they have exhausted their appeal options.

The change could lead to the release of thousands of prisoners, including Lula.

The left-winger led Brazil between 2003 and 2010, but was jailed last year.

He was favourite to win last year's presidential election but was imprisoned after being implicated in a major corruption investigation. The right-wing candidate Jair Bolsonaro – dubbed the "Trump of the tropics" – went on to win comfortably.

The corruption scandal, known as Operation Car Wash, initially centred on the state-run oil company Petrobras, but subsequently billions of dollars of bribes were uncovered – and dozens of high-profile business leaders and politicians were jailed.

Lula has consistently denied all the accusations against him and claims they are politically motivated.

Justices voted to reinterpret the country's penal code in a six-five vote issued on Thursday.

It overturns a three-year-old ruling which threatened suspects with immediate prison time before their appeals were exhausted. The measure was seen as helping prosecutors secure convictions and unravel the major corruption probe by encouraging suspects to negotiate plea deals.

Lula's lawyers have already called for his release in response to the judgement.

Supporters of Brazil's former president Luiz Inacio Lula da Silva protest outside the Supreme Federal CourtI

Lula supporters rallied outside the court on Thursday