An appeals court in Brazil has upheld a conviction for corruption imposed last July on ex-President Luiz Inacio Lula da Silva.

While he can still take his appeal to a higher court, the decision could rule Lula out as a candidate for October’s presidential election.

The ex-leader, who governed from 2003 to 2011, had been favourite to win.

Ahead of the ruling, Lula said he would continue fighting “for the dignity of the Brazilian people” until he died.

On Wednesday, two of the three judges at the appeals court in the city of Porto Alegre said Lula had broken the law by accepting a seafront apartment from a construction company involved in a major corruption scheme.

They voted that his original sentence should be increased from nine-and-a-half years to 12 years and one month.

The third judge on the panel is voting now, and his decision could determine how Lula’s expected appeal will proceed.

What does the ruling mean?

The ruling is a severe blow to Lula’s ambitions to become president for a third term in elections scheduled for 7 October.

Under Brazilian electoral rules, candidates cannot run for office if they have prior convictions.

But Lula’s lawyers argue that rule cannot come into force until the defendant has exhausted all of his appeals.

Is the ban final?

No, there is a way around it. Lula could ask the Supreme Court to lift the ban and, if the court were to accede to his request, he could stand for office.

However, time is of the essence as Lula will need to have registered his candidacy by 15 August.

What exactly was Lula convicted of?

When left-winger Lula rose to power in 2003, he promised an end to shady, corruption-ridden politics. Then in 2005 a huge vote-buying scandal nearly cost him his job.

Despite that, he won the support of the poor by pouring billions of dollars into social programmes, and left office in 2011 with record approval ratings.

It was Brazil’s biggest-ever corruption scandal, Operation Car Wash, which triggered Lula’s current legal woes.

The investigation, which began in March 2014, sucked in more than 80 politicians and members of the business elite.

In 2017, Lula was found guilty of accepting a beachfront apartment from an engineering firm in return for help in winning contracts for Petrobras, Brazil’s state oil company.

That conviction was confirmed by Wednesday’s ruling.

He also faces other charges of money laundering, influence peddling and obstruction of justice. He has repeatedly denied those claims.

Will he go to jail now?

Even though the 72-year-old was sentenced to in July 2017 and that conviction has now been upheld, he will not be sent to prison straight away.

Lula can appeal against his conviction at a higher court, and if that court rules in his favour, he will remain free.

What effect will the ruling have?

The ruling will cause anger among Lula’s many loyal supporter and members of his Workers’ Party. Thousands of them gathered in Porto Alegre, where the court met, to show their support.

Divisions in Brazilian society are likely to deepen following this decision. Lula’s supporters will argue that the conviction is an attack on democracy and his critics will see the appeal court’s decision as proof that the Workers’ Party is corrupt.

Will the Workers’ Party put up an alternative candidate?

Ahead of the ruling, local Workers’ Party leader Cleiton Leite Coutinho told the BBC: “The Workers’ Party does not have a plan B, C or D today, our plan is called Luiz Inacio da Silva.

“Either Lula is a candidate, or we are going out on the streets, we will not accept any intrusion into Brazil’s democracy.”

The party can put forward an alternative candidate as late as 20 days before the election.

What’s likely to happen next?

Lula is unlikely to give up his fight for the presidency.

His lawyers will be exploring every possible avenue for him to run in October’s election. All along, he has maintained he is innocent and that the charges against him are politically motivated.