Former President Luiz Inacio Lula da Silva gestures to supporters at the headquarters of the Metalworkers' Union in April before his surrender to federal police.
CNN  — 

Brazil’s top electoral court has barred former President Luiz Inacio Lula da Silva from running for reelection because of a corruption conviction, just weeks before Brazilians go to the polls for a vote in which he was considered a frontrunner despite being in prison.

Six of seven justices from the Supreme Electoral Tribunal in Brasilia ruled that Lula was ineligible to run in October, while one voted in favor in a hearing stretching late into Friday night.

Brazilian law bars candidates whose conviction has been upheld on appeal.

Universally known as Lula, Lula da Silva is a founding member of Brazil’s only socialist political party, Partido dos Trabalhadores (PT), the Workers’ Party.

A former metalworker and union leader, he rose through the political ranks to serve two terms as president between 2003 and 2011. He left office with a 90% approval rating, after his policies helped to lift millions of Brazilians out of poverty.

But he has been in jail since April after he was sentenced to 12 years for corruption and money laundering. The accusations against him emerged after he left office in 2011.

The 72-year-old has strongly denied any wrongdoing. His defense said he was a victim of political persecution.

Lula da Silva’s lawyers can appeal the latest court decision.

The Workers’ Party said in a statement: “We will present all the appeals to the courts so that the political rights of Lula, as provided by law and in international treaties ratified by Brazil, are recognized.”

Lula da Silva has been in prison since he surrendered to federal police in April. Since then, PT politicians and supporters have held rallies calling for his release and claiming his innocence.

He was registered as the PT’s candidate in the upcoming vote in August.

At the time, he said in a statement on his official website that he had submitted his candidacy “with the certainty that I can do much to take Brazil out of one of the worst crises in history.”

He also accused political opponents of convicting him without evidence in an attempt to take him out of the election.

Lula Da Silva delivers a speech during the Workers Party National Congress to elect its new president in Brasilia in June 2017.

His conviction stemmed from a wide-ranging corruption investigation into the state-run oil company Petrobras, dubbed “Operation Car Wash.”

Lula da Silva was accused of benefiting from the renovation of a triplex in a beach town near Sao Paulo by the construction company OAS. The charges were connected to 3.7 million reais’ worth of bribes ($1.1 million) received from OAS through the beachfront apartment. In return, Lula da Silva helped the builder acquire contracts from the oil company, prosecutors charged.

Lula da Silva was initially found guilty of the charges in July 2017.

In January, an appeals court unanimously upheld the corruption and money laundering charges against him, and he was handed the prison sentence.

He was first questioned by police about the corruption allegations in March 2016. Lula da Silva’s wife, Marisa Leticia Lula da Silva, who died in February 2017, and six others also were charged.

Born into a working class family, Lula da Silva left school and began working at age 12. Unhappy with the lack of political representation of the working class in Brazil, he decided to get involved in politics and helped found the Workers’ Party in 1980.

He was friends with the late Cuban leader Fidel Castro, who supported his political career, and attended Castro’s funeral in 2016.