A supporter holds a mask in the likeness of the Brazil's jailed former President Luiz Inacio Lula da Silva, during a campaign rally outside federal police headquarters where da Silva is in prison for corruption, in Curitiba, Brazil, Tuesday, Sept. 11, 2018. (AP Photo/Eraldo Peres)

Brasília - A Brazilian supreme court judge on Wednesday issued an order that could see former president Luiz Inacio Lula da Silva soon released from prison, where he is serving a 12-year term for graft.

Justice Marco Aurelio Mello ruled that all prisoners in Lula's situation -- those whose convictions have been confirmed by a second court -- should be freed while final appeals were under way if their lawyers request it.

The decision was unexpected and sent a jolt through Brazil's political and legal circles just ahead of far-right president-elect Jair Bolsonaro's inauguration on January 1.

Up to now, the country's courts had rejected multiple efforts by Lula's lawyers to win the ex-leader's release. The full supreme court had said it was to convene on April 10, 2019 to consider the matter abruptly decided by Mello. 

Lula's imprisonment prevented him from contesting October elections that were won by Bolsonaro, who lambasted the former far-left leader and repeatedly tied Lula's Workers Party to corruption.

Lula has said from his cell that he would have easily triumphed in that election -- something borne out by voter surveys that showed the ex-president remained broadly popular with Brazilians despite his conviction.

- Claims innocence -

The head of the Workers Party, Gleisi Hoffman, tweeted immediately after publication of the judge's order that lawyers have already put in a request for Lula's release.

Lula, 73, was incarcerated in April this year after being found guilty of accepting a seaside apartment as a bribe from a Brazilian construction company, BTP, in return for public works contracts during his 2003-2010 time in office.

He is the subject of five other corruption and money laundering investigations but insists he is innocent of all charges.

In November, he and his successor -- fellow Workers Party member Dilma Rousseff -- were accused of receiving bribes with money diverted from state-owned oil giant Petrobras, which sits at the center of a vast corruption probe in Brazil known as Car Wash.

He has also been accused of money laundering in his dealings with Equatorial Guinea after he left the presidency.

The 11 justices sitting on the supreme court had ruled in 2016 that a sentence had to be carried out if an initial appeal failed. That was upheld to put Lula behind bars.

- Popular leader -

Lula, who has been held in a prison in the southern city of Curitiba, has said the charges against him and his incarceration were meant to keep him out of this year's election.

During his two terms at the helm of Latin America's biggest economy, Lula rode high on Brazil's good fortune being a major commodity exporter as China's appetite for its resources expanded. The country also discovered massive off-shore deepwater oil fields, adding to its national wealth.

He earned the gratitude of millions of Brazilians for redistributing wealth to haul them out of poverty, and oversaw Brazil's successful bids to host the World Cup soccer tournament in 2014 and the Olympic Games in Rio de Janeiro in 2016.

But under Rousseff, Brazil's prosperity got wiped out in the worst recession on record. She ended up being impeached and booted from the presidency for cooking the government's books.

AFP