A Brazilian court has upheld the conviction of the former president Luiz Inácio Lula da Silva for corruption and money laundering, in a ruling that complicates his plans to run for a third term and marks an extraordinary change of fortune for the most popular leader in modern Brazilian history.

Three judges at the appeals court in Porto Alegre voted unanimously on Wednesday to uphold the sentence that Lula was handed by a lower court, and increased the penalty from nine and a half years to 12 years and one month.

The ruling prompted protests across Brazil, and protesters set fire to tyres and blocked streets in Porto Alegre and São Paulo.

Lula leads early polls for October’s presidential election, but the latest court decision means that he could be barred from running.

The former union leader says he is innocent and the process is politically motivated to stop him from standing for an election. His supporters have called it an attack on democracy.

Brazilians were glued to coverage of the case, with news sites and television broadcasting live from the courtroom.

Troops and police sealed off the court building in central Porto Alegre, but tens of thousands of Lula’s supporters – who had travelled from all over Brazil – gathered in a nearby avenue before a line of impassive riot police.

Marilia Vieira, 48, a teacher from Brasília, had spent 36 hours on a bus to get there.

“The struggle will continue. And it will get more serious,” she said.

Lula’s lawyers Cristiano Martins and Valeska Martins attacked the verdict and pledged to refer a complaint to the United Nations human rights committee.

“The whole process from the very beginning has been a legal farce masquerading as justice,” they said in a statement.

Lula served two mandates from 2003-2010, then helped his Workers’ party successor Dilma Rousseff win two more, before she was impeached for breaking budget rules in 2016 in a controversial process she denounced as a “coup”.

She joined leftists and jurists across the world in attacking the legal proceedings against Lula. Even Diego Maradona posted a selfie on Facebook holding a Brazil team shirt with “LULA and 18”, captioned: “Dear Lula, Diego is with you.”

The verdict confirmed a sentence handed to Lula in July by Sérgio Moro – a campaigning judge known for tough sentencing in corruption cases and increased jail time.

Lula was found guilty of receiving a seaside duplex apartment worth about £540,000 ($755,000) from a construction company called OAS. Prosecutors said the gift was part of a multibillion-dollar bribe scheme controlled by the former president at the state-run oil company Petrobras.

Lula’s lawyers argued that he never owned the apartment and said they would appeal against the decision.

João Gebran Neto, the judge leading the verdict, placed the apartment into the wider context of the graft network, which cost Petrobras billions of dollars.

“The defendant in truth was the guarantor of the bigger scheme, for which he acted behind the scenes, which aimed in a surreptitious way to increase the financing of parties,” he said.

The decision means Lula is legally ineligible to stand under a “clean slate” law, said Silvana Batini, a professor of electoral law at the Getúlio Vargas Foundation in Rio de Janeiro.



But Lula had plenty of appeal options, she said. His party says he will register his candidacy on 15 August, and a final decision by electoral courts is unlikely before 17 September.



“There are legal formalities that will let President Lula start the electoral process even though he has been convicted,” Batini said.



Running second to Lula in polls is Jair Bolsonaro, a far rightwing lawmaker and former army captain. But if Lula is definitively removed from contention, the race is left wide open, said Geraldo Tadeu, an adjunct professor of political science at the State University of Rio de Janeiro.



“From the electoral point of view, the game goes back to zero,” he said.



Many in Porto Alegre said they thought Lula was guilty of involvement in graft that benefited his party, even if the specific case being judged was weak.



“He had to know,” said Gerson Praxedes, 67, an accounting clerk.



Others expressed concern over the increasingly bitter polarisation of Brazilian politics.



“We see extremes of left and right,” said Tanice Korman, 29, who works for the state government’s environmental protection agency. “We don’t have politicians who represent the population.”



Late on Wednesday, Lula addressed a crowd of thousands of supporters in São Paulo, saying that his conviction had been engineered by upper-class Brazilians who could not tolerate the gains poorer Brazilians had made under his party’s rule.

In a fiery speech, Lula vowed to fight on.

“While this heart still beats, and while these eyes still see and while this brain still thinks, the struggle is not over,” he said. “This country will prove that the poor people were never the problem. The poor people are the solution.”