An appeals court in Brazil has unanimously upheld a corruption conviction 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.
Speaking at a rally in Sao Paulo after the ruling, Lula said he would still contest the presidency.
"I know I haven't committed any crime," he told thousands of his supporters.
On Wednesday, all three judges at the appeals court in the city of Porto Alegre said Lula had broken the law by accepting special favours over a seafront apartment from a construction company involved in a major corruption scheme.
They increased his original sentence from nine-and-a-half years to 12 years and one month in jail.
Even though the 72-year-old was sentenced in July 2017 and that conviction has now been upheld, he could remain out of prison for many months if he takes his appeal all the way to the Supreme Court.
Presidential hopes fade: Katy Watson in Porto Alegre
Lula supporters weren't contemplating any other scenario than him winning the appeal. They want him as their candidate in October's elections and they say this conviction is designed to stop him running.
But his critics will be pleased. They want him locked up in jail for the crimes he's been accused of. They believe he and his Workers' Party are corrupt and justice needs to be done.
Lula and his lawyers say they will explore all avenues to get him absolved. But the fact that it was a unanimous vote will make it harder to convince other courts.
As for whether he will run for presidency, he has said he will keep campaigning, no matter the verdict.
The appeals process could buy him time to stay in the race for a few months but with a criminal conviction, another Lula term is looking much less likely.
What exactly was Lula convicted of?
When left-winger Lula rose to power in 2003, he promised an end to 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, that triggered Lula's current legal woes.
The investigation, which began in 2014, sucked in more than 80 politicians and members of the business elite.
In 2017, Lula was found guilty of accepting an upgrade to a beachfront flat he was buying 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 Lula still run for president?
The elections are scheduled for 7 October, and under Brazilian electoral rules, candidates cannot run for office if they have convictions.
But Lula's lawyers argue that the rule cannot come into force until the defendant has exhausted all of his appeals.
Even then, Lula could ask the Supreme Court to lift the ban and, if the court were to agree, he could stand for office.
However, time is of the essence as Lula will need to have registered his candidacy by 15 August.
What will be the effect on Brazilians?
The ruling will cause anger among Lula's many supporters and members of his Workers' Party. Thousands of them gathered in Porto Alegre, where the court met.
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.