With his failure to secure a writ of habeas corpus from Brazil’s supreme court Luiz Inácio Lula da Silva is now much closer to prison than realising the return to the presidency he has sought to navigate through his mounting legal woes.

Wednesday’s six-five ruling against him after a rancorous 11-hour session amid heightened political tensions means the popular former union boss can now be detained to start a 12-year and one month prison sentence for corruption involving a beachside apartment.

When the former president will be detained and how much jail time he eventually serves remain uncertain. But the likelihood that he will now be arrested, possibly within days, all but ends any faint hope Lula retained of disputing October’s presidential elections.

Instead he now faces spending the next few months desperately trying to get any jail time transformed into a more amenable house arrest at least. Even if he manages that it will be of limited comfort. Several of the other corruption cases Lula is facing are edging towards verdicts. More harsh sentences against him are thought likely.

All this will leave his Workers Party without a competitive candidate in October’s race. It has sought to portray the corruption cases against Lula as a political witch-hunt designed to remove the contest’s clear front-runner. In a statement it labelled Wednesday’s ruling “a tragic day for Brazilian democracy”.

Decision celebrated

But federal prosecutors celebrated the court’s decision as a victory against the mounting efforts among politicians and senior figures in the judiciary to disarm the sprawling Car Wash investigations into corruption between elected officials and private-sector contractors.

“Today the supreme court had the chance to bury Car Wash or bury impunity and corruption. The desire to bury corruption won out,” said prosecutor Diogo Castor de Matos speaking after the court verdict.

A granting of habeas corpus would have guaranteed Lula’s freedom, potentially for years, while he exhausted all the legal avenues provided for in Brazil’s lethargic judicial system appealing against his conviction last year in the apartment case. It could also have set a precedent that would have prevented others caught up in the investigations from having to start their sentences once an initial conviction is upheld on appeal, a move prosecutors said could fatally undermine the investigations.

But Wednesday’s session highlighted that powerful members of the supreme court, led by the controversial justice Gilmar Mendes, are increasingly uncomfortable with the rigour of lower court judges in detaining members of the country’s political and economic elite.

In voting in favour of granting Lula habeas corpus Mendes criticised lower courts for insisting that those convicted of crimes automatically start their sentences after their convictions have been upheld on appeal. “We have always said that prison is a juridical possibility, not an obligation,” he said explaining his decision.

Though defeated on Wednesday Mendes and those who voted with him will likely try again to protect those convicted in two courts from starting their sentences as they are seeking to have the supreme court revise its own decision of November 2016 to allow the execution of sentences once an appeal has been heard.

This debate over judicially-sanctioned impunity has been further heated by a statement from the head of Brazil’s army. General Eduardo Villas Bôas said ahead of the supreme court session the army repudiated impunity, widely interpreted as a call to reject Lula’s habeas corpus request. The intervention drew widespread condemnation.

Brazil’s military has largely stayed out of politics since it returned power to the civilians in 1985.