IT WAS a moment many Brazilians thought they would never see. On April 7th, after spending three days among his supporters in the headquarters of the metalworkers’ union in São Bernardo do Campo, a suburb of São Paulo, Luiz Inácio Lula da Silva, Brazil’s former president, handed himself over to the federal police. He will now begin a 12-year prison sentence for corruption and money laundering. His imprisonment almost certainly marks the end of his bid to return to the presidency in elections to be held in October. But it will have a big influence on those elections, which are shaping up to be the most contentious and consequential in decades.

Brazilians were transfixed by rolling television coverage of Lula’s final hours of freedom. A standoff began on April 5th, when Sérgio Moro, the federal judge who oversees Brazil’s Lava Jato (“Car Wash”) corruption investigation, now in its fifth year, issued a warrant for Lula’s arrest and set him a deadline of 5pm the following day to turn himself in. The ultimatum followed a decision by the supreme court (the STF) on the previous day to reject a habeas corpus petition by Lula’s lawyers.

As news helicopters thundered overhead, thousands of activists from Lula’s Workers’ Party (PT) converged on the union headquarters. Mr Moro’s deadline came and went, while Lula negotiated the terms of his surrender with the police. He let the suspense build. On the morning of April 7th he heard a mass in memory of his late wife. He then addressed supporters, reasserting his innocence and accusing his enemies of fabricating the charges to foil his presidential bid. In the evening he left the building on foot, making his way through crowds of supporters to surrender to police.

Lula divides public opinion like no other Brazilian politician. Despite his conviction, 37% of Brazilians say they would vote for him in October’s election, making him the most popular candidate by far. Millions of Brazilians escaped poverty during his presidency, from 2003 to 2010. “If it is a crime to send poor blacks to university, to enable the poor to buy cars, to travel by plane, to own their own home...if that’s the crime I committed, I will continue to be a criminal,” Lula told his supporters on April 7th.

In July 2017 Mr Moro found him guilty of accepting a beach-front apartment from OAS, a construction company, in return for intervening on the firm’s behalf to secure government contracts. He remained free while he appealed, campaigning across the country and drawing enthusiastic crowds, particularly in the poor north-east.

Lula’s election prospects were dealt a severe blow in January, when a higher court rejected his appeal against his conviction. Under Brazil’s Ficha Limpa (“Clean Record”) law, those with convictions confirmed by the first appeal court are to be barred from holding public office for eight years. In 2016 the STF ruled that such convicts should begin their sentences immediately. Lula’s defence team played for time, filing procedural motions at the appeal court and making its petition for habeas corpus to the STF. The STF rejected it on April 5th by six votes to five, clearing the way for Lula’s incarceration.

His imprisonment makes the election campaign less predictable. Some of Lula’s supporters may back candidates from other left-of-centre parties, such as Ciro Gomes or Marina Silva, former ministers in his government. The PT may replace Lula with another candidate, probably Fernando Haddad, an ex-mayor of the city of São Paulo, or Jaques Wagner, a former governor of the state of Bahia. Neither has the support of more than 3% of voters, but Lula’s endorsement could change that. “They would likely perform much better than current polls suggest,” says Thomaz Favaro of Control Risks, a consultancy.

Lula’s jailing is a blow for Jair Bolsonaro, a right-wing demagogue who portrays himself as the antithesis of Lula. He is second in the polls, with the support of 16% of voters. He had hoped to face Lula, the only candidate with any chance of winning who has higher negative ratings than he does, in a run-off election, scheduled for October 28th. With Lula out of the race, support for Mr Bolsonaro may now decline. That could boost the chances of a centrist candidate such as Geraldo Alckmin, a four-term governor of São Paulo state.

Although many Brazilians will see the election as a referendum on Lula’s conviction and incarceration, the issues at stake go beyond that. Voters have an opportunity to elect a new generation of politicians to congress and state legislatures who reject the corrupt practices of today’s lawmakers. The next president and congress will have to decide whether to carry out contentious measures like reforming pensions. These are needed to give long-term stability to the economy, which is now recovering from its worst-ever recession.

Lula’s defence team has not given up hope of securing his release before election day. Some STF justices favour a review of their decision in 2016 mandating prison for criminals whose conviction is affirmed by an appeal court. The court could change this, saying that a second appeal court must confirm a conviction before a criminal is jailed. Lula would then be released until his conviction is confirmed by the superior court of justice, which could take months or even years. This could conceivably happen before the October vote. Lula would then be free to campaign for another candidate, or to resurrect his own candidacy while seeking an injunction exempting him from the Ficha Limpa law. Captive or free, Lula remains a powerful force in this year’s election.