A Brazilian judge has ordered that the former President Luiz Inácio Lula da Silva turn himself in to police by late afternoon on Friday to begin serving a 12-year sentence for corruption.
On Thursday, the Supreme Court ruled against Lula's plea to remain free while he appealed against his conviction.
Lula claims the charges are politically motivated, and designed to prevent him from running for president in October.
He had been the favourite to win.
In his order, Federal Judge Sergio Moro said that the 72-year-old must present himself before 17:00 local time (20:00 GMT) on Friday at the federal police headquarters in the southern city of Curitiba.
Judge Moro said that a special cell "was prepared in advance... in which the ex-president will be separated from other prisoners, with no risk for his moral or physical integrity".
After the judge's announcement several hundred of Lula's supporters rallied outside the metalworkers union near São Paulo.
The charges came from an anti-corruption investigation known as Operation Car Wash, which has implicated top politicians from several parties.
Lula served as president between 2003 and 2011. Despite a lead in opinion polls ahead of October's election, he remains a divisive figure.
A new political crisis
By Katy Watson in São Bernardo do Campo, São Paulo state
Outside the metalworkers union, hundreds of people had gathered in a bit of a scramble - the rally was hastily brought forward from Friday after the arrest warrant was issued. People were carrying placards saying "Down with the coup" and "No to prison".
Leaders of social movements and unions spoke to the crowd, telling them that they weren't going to let Lula get arrested. They were prepared to put up a fight.
The question many people are wondering is whether Lula will give himself up voluntarily or whether he will make a show out of this and refuse to bow out in silence.
The Brazilian legal system usually goes at a glacial speed - so the pace of this process has surprised everyone. Brazil is in a state of political crisis and it's likely to get worse in the coming days.
Who is Lula?
A former metalworker and trade union activist, he was the first left-wing leader to make it to the presidency in Brazil in nearly half a century.
During his presidency, Brazil experienced its longest period of economic growth in three decades allowing his administration to spend lavishly on social programmes.
Tens of millions were lifted out of poverty thanks to the initiatives taken by his government and he left office after two consecutive terms (the maximum allowed in Brazil) with record popularity ratings.
What is Operation Car Wash?
In 2014, after Lula left office, prosecutors started investigating allegations that executives at the state oil company Petrobras had accepted bribes in return for awarding contracts to construction firms.
The investigation, dubbed Operation Car Wash, uncovered a huge web of corruption involving top-level politicians from a broad spectrum of parties taking kickbacks.
Lula himself was convicted of receiving a renovated beachfront apartment worth some 3.7 million reais ($1.1m, £790,000), as a bribe by engineering firm OAS.
The defence says Lula's ownership of the apartment has never been proven and that his conviction rests largely on the word of the former chairman of OAS, himself convicted of corruption.
What does Lula say?
Lula has described the battle against his conviction and prison term as a continuation of his fight against Brazil's military rule, which came to an end in 1985.
"I did not accept the military dictatorship and I will not accept this dictatorship of the prosecutors," he told a gathering of supporters on Monday.
What happens next?
Although he has been told to turn himself in, it is not certain that he will go to jail for 12 years.
He has not exhausted his appeals yet. There are two higher courts which he can still turn to, the Superior Court and the Supreme Court - the latter has only ruled for far on whether he should go to jail pending further appeals, rather than on the underlying case.
Neither of those courts would re-examine whether Lula was guilty of corruption. They would look into whether legal procedures were followed correctly and whether his constitutional rights were breached.
This process could take months or even years. If either court were to rule in Lula's favour, his conviction could be annulled and he would be released.
What about the election?
Under a 2010 Brazilian law called "clean slate law", no one convicted of a crime upheld on appeal can run for elected office for at least eight years.
That law would rule Lula out from running for the presidency in October. However, exceptions have been made to the law before.
The decision as to whether Lula can stand for president will rest with the Superior Electoral Court (TSE).
The TSE will not make a decision on whether Lula can run or not until he has registered as a candidate and he has until 15 August to do so. So we may not know for months to come whether he will be able to stand.