RIO DE JANEIRO — His fist thrust in the air, former President Luiz Inácio Lula da Silva of Brazil triumphantly walked out of prison Friday, after the Supreme Court issued a broad ruling that allows defendants to remain free while their appeals are pending.

Though Mr. da Silva cannot run for office unless his criminal convictions are overturned, his mere release could upend Brazil’s politics by pitting him as a fiery, leftist rival to President Jair Bolsonaro, whose far-right policies have left the country deeply polarized.

The charismatic Mr. da Silva, 74, universally known as “Lula,” is widely expected to plunge back into the political fray, bolstered by his longstanding popularity: As president, he launched programs that lifted millions out of poverty, expanded access to higher education and promoted racial equality.

On Friday, he walked out of a police building in the southern city of Curitiba shortly after 5:30 p.m., raised a fist and waded into a crowd of supporters waving his party’s trademark red flag. He kissed babies and pulled supporters into bear hugs before addressing the crowd.