RIO DE JANEIRO — Luiz Inácio Lula da Silva, a former Brazilian president who wielded enormous influence over Latin America for decades, was released from prison Friday on grounds that he was denied due process, sending political shock waves through a country bitterly divided by his imprisonment.

The decision came after the Brazilian Supreme Court ruled Thursday night that defendants should have the opportunity to exhaust all of their appeals before their imprisonment, a decision that has the potential to benefit thousands of people, including dozens of powerful politicians ensnared by the sprawling corruption probe known here as Operation Car Wash.

Judge Danilo Pereira Júnior ruled Friday afternoon that he didn’t see any reason to keep Lula jailed and has ordered him released while he appeals his conviction, which led to a sentence of 12 years in prison last year.

“There are no grounds for the continuation of this provisional criminal enforcement,” the judge declared.

A charismatic leader known for his knack for political theater, Lula emerged from the prison in the southern Brazilian city of Curitiba at dusk, dressed in black, beside leaders of his Workers Party. Hundreds of supporters thronged him, wearing red and chanting his name.

“You have no idea of the meaning of me being here with you,” he told them moments after his release. “I, who have been speaking to the Brazilian people through all my life, did not think that I would be able to speak today. … Every day you were the democracy’s fuel I needed to exist.”

He condemned the people who had imprisoned him. “They did not jail a man, they tried to kill an idea, and ideas don’t disappear,” he said.

Lula’s imprisonment last year fundamentally altered the arc of Brazilian politics. He was leading in the polls and appeared poised to reclaim the presidency. His jailing on charges of corruption cleared the path for Jair Bolsonaro, a former fringe politician known for making incendiary comments and lamenting the collapse of Brazil’s dictatorship, to win the election.

His release marks another political pivot point in Latin America’s largest country. Supporters are planning rallies. There are reports he will be invited to the inauguration of Argentine president-elect Alberto Ángel Fernández, who has feuded with Bolsonaro and called for Lula’s release.

When Lula left office in 2010, he had an approval rating of 80 percent and enormous popularity across the country, particularly among the poor, whose travails he made central to his governance. His social welfare programs are credited with helping to bring millions out of poverty.

Now he is widely expected to enter the political realm once more, potentially further polarizing the country. Lula said he plans to head out across the country.

“The doors of Brazil will now be open,” he said.

Critics of Lula expressed outrage at the ruling.

“They release prisoners and disarm citizens,” said Eduardo Bolsonaro, son of the president and a federal congressman. “Poor Brazilians.”

But those on the left, both inside and outside of Brazil, cheered his release.

“We are pinching ourselves to make sure this is all true,” Gilberto Carvalho, Lula’s former chief of staff and one of the leaders of the Workers Party, told The Washington Post.

U.S. Sen. Bernie Sanders (I-Vt.), a leading candidate for the Democratic nomination, tweeted his support. “As President, Lula has done more than anyone to lower poverty in Brazil and to stand up for workers,” he said. “I am delighted that he has been released from jail, something that never should have happened in the first place.”

The Brazilian supreme court's 6-5 ruling Thursday, which overturned an earlier decision, was a significant blow to Operation Car Wash. Appeals for release are already flooding the courts. Prosecutors have warned that it could deprive them of the necessary tools to root out corruption in a country long bedeviled by it. Some, particularly the wealthy, may now be able to manipulate Brazil's byzantine appellate system to delay imprisonment, perhaps indefinitely.

The legal path ahead of Lula, Brazil’s first working-class president, remains treacherous. He faces eight other trials on charges of corruption and money laundering. In 2016, as part of the Operation Car Wash investigation, Lula was accused of peddling government influence for renovations to his beachfront property.

Marina Lopes in Sao Paulo contributed to this report.