Brazil’s former president Luiz Inácio Lula da Silva has been released from prison after a supreme court ruling that delighted his supporters and infuriated followers of the far-right president Jair Bolsonaro.

Lula, who was serving a 12-year corruption sentence, was greeted by hundreds of supporters wearing red vests emblazoned with his face outside the federal police headquarters in the city of Curitiba, where he had been imprisoned for 580 days.

In a speech to the crowd, Lula thanked party militants who had camped outside throughout his imprisonment, and attacked the “rotten side” of the police, prosecutors, tax office and justice system for jailing him.

“They did not imprison a man. They tried to kill an idea,” he said. “Brazil did not improve, Brazil got worse. The people are going hungry. The people are unemployed. The people do not have formal jobs. People are working for Uber – they’re riding bikes to deliver pizzas.”

Lula was imprisoned in April 2018 after a sentence for corruption and money laundering handed down by the controversial judge Sergio Moro was upheld by an appeal court. He has always proclaimed his innocence and argued the case against him was politically motivated.

On Thursday, Brazil’s supreme court ruled defendants could only be imprisoned after all appeals to higher courts had been exhausted, paving the way for Lula and another 5,000 prisoners to be freed.

The decision followed revelations on investigative website the Intercept Brasil that Moro had colluded with prosecutors leading the sweeping corruption investigation, known as Operation Car Wash, into bribes and kickbacks at the state oil company Petrobras that imprisoned Lula, powerful business leaders, middlemen and politicians from his Workers’ party and its political allies.

Lula begins prison sentence in Brazil after giving himself up to police Read more

Polls had showed Lula was leading in last year’s presidential election, but the conviction removed him from the race, giving Bolsonaro a clear run.

Bolsonaro then named Moro his justice minister, heightening the sense of injustice. The president appeared to recognize the former judge’s contribution in a speech on Friday. “If he hadn’t accomplished his mission, I wouldn’t be here either,” Bolsonaro said.

As president from 2003 to 2010, Lula presided over an extraordinary period of economic growth and reduction of inequality as innovative cash transfer schemes took tens of millions out of poverty. Even in prison he has cast a long shadow over Brazilian politics – and his release is only likely to widen bitter political divides.

“A free Lula increases polarisation, which could increase Bolsonaro’s support,” said Maurício Santoro, a professor of international relations at the State University of Rio de Janeiro. “On the other hand, his charisma and political ability will make the opposition more effective against Bolsonaro. As leader of the opposition, Lula has more international prestige than the president.”

Bolsonaro did not immediately react to Lula’s release, but Eduardo Bolsonaro, the president’s congressman son, tweeted that leftists celebrating the news were “shitting on society’s head”.

Controversy swirled around the supreme court decision – the third time it had changed its mind on the issue in 10 years. Richer Brazilians have traditionally dragged out legal processes to remain at liberty until their crimes became erased by the statute of limitations.

Others imprisoned in the same corruption investigation have also requested release – including Lula’s former chief of staff, José Dirceu, João Vaccari Neto, the party’s former treasurer, and Renato Duque, a Petrobras executive embroiled in the scandal.

Nor are Lula’s legal problems over – he faces eight other cases, according to the Folha de S.Paulo newspaper. His lawyers have called this legal blitzkrieg “lawfare”. In one case, he was handed a 12-year, 11-month sentence over his alleged ownership of a country house – a decision the appeal court will consider next week. Brazil’s Congress is also considering measures that could effectively revert the supreme court’s decision.

But Lula was keen to show he had lost none of his fighting spirit. Earlier on Friday, his official Twitter account posted a video of him working out to the soundtrack from Rocky.