SAO BERNARDO DO CAMPO, Brazil -- Latin America's largest nation prepared for what would have been unimaginable just a few years ago: the arrest of former President Luiz Inacio Lula da Silva, a once wildly popular leader whose administrations were credited with bringing millions out of poverty in one of the world's most unequal countries.

Federal judge Sergio Moro, seen by many in Brazil as a crusader against graft, gave da Silva until 5 p.m. local time Friday to turn himself in and begin serving a sentence of 12 years and one month for a corruption conviction.

Moro's warrant Thursday evening came after Brazil's top court, the Supreme Federal Tribunal, voted 6-5 to deny a request by the former president to stay out of prison while he appealed a conviction that he contends was simply a way to keep him off the ballot in October's election. He is the front-running presidential candidate despite his conviction.

In a statement, Moro said he was giving da Silva the opportunity to come in of his own accord because he had been Brazil's president. He also said a special cell away from other inmates had been prepared for da Silva at the jail in Curitiba, where Moro ordered da Silva to present himself.

Last year, Moro convicted da Silva of trading favours with a construction company in exchange for the promise of a beachfront apartment. That conviction was upheld by an appeals court in January.

The speed with which Moro issued the warrant surprised many, as legal observers said there were technicalities from da Silva's upheld appeal that would not be sorted out until next week.

Such technicalities "were simply a pathology that should be eliminated from the judicial world," Moro said in his statement.

Late Thursday, thousands gathered outside a metallurgical union in Sao Bernardo do Campo, a Sao Paulo suburb where the ex-president universally known as "Lula" got his start as a union organizer. Hundreds spent the night sleeping on the street. Early Friday, da Silva waved to supporters from a window at the union but did not speak.

"Why are they in a rush to arrest him?" said former President Dilma Rousseff, who succeeded da Silva and in 2016 was impeached and ousted from office. "They fear that Lula would get a favourable decision in (a higher appeals) court. That is part of the coup that removed me from the presidency."

It's unclear whether da Silva will present himself in the city of Curitiba, about 260 miles (417 kilometres) southwest of Sao Paulo, or perhaps instead force police to come and get him. The latter would be a logistical nightmare for authorities, given the thousands of supporters outside and heavy Friday traffic in Sao Paulo, South America's largest city.

"I don't see why he should turn himself in just because judge Moro had an anxiety crisis," said Sen. Lindbergh Farias. "I think they should have to go through the embarrassment of coming here and taking him in front of all these people."

"That footage will be seen around the world and it will be historic," he added.

However it happens, the jailing of da Silva will mark a colossal fall from grace for the man who became a world celebrity and left office with approval ratings over 80 per cent.

Former U.S. President Barack Obama once called da Silva the "most popular politician on Earth."

Since leaving office, things have steadily gotten worse for da Silva, who has been charged in several corruption cases. He has always maintained his innocence while continuing to campaign across the country the past year. Despite his legal troubles, he leads preference polls to return to office -- if by some chance he is allowed to run.

Like so much in a nation that has become deeply polarized, that da Silva would soon be behind bars was being interpreted differently by supporters and detractors.

"Brazil scored a goal against impunity and corruption," said Congressman Jair Bolsonaro, a right-leaning former army captain who is second in the polls after da Silva.

"Lula is one of us. He knows what it is like to have a tough life and loves the poor more than the rich," said Antonio Ferreira dos Santos, a 43-year-old bricklayer who was keeping vigil outside the union.

In a sign of possible friction on the horizon, within minutes after Moro's arrest warrant, a fight broke out in front of the Lula Institute in Sao Paulo between hecklers and supporters of da Silva. One heckler was punched in the face and subsequently got hit by a passing vehicle as he was falling. He was taken to nearby hospital and police arrived.

Earlier Thursday, the head of the Workers' Party insisted that da Silva, 72, would be the party's candidate in October. His lawyers put out several statements saying they were filing injunctions in hopes of keeping him out of jail.

Technically, beginning to serve his sentence would not keep da Silva off the ballot. In August, the country's top electoral court makes final decisions about candidacies. It was expected to deny da Silva's candidacy under Brazil's "clean slate" law, which disqualifies people who have had criminal convictions upheld. However, da Silva could appeal such a decision, though doing so from jail would be more complicated.

Da Silva is the latest of many high-profile people to be ensnared in possibly the largest corruption scandal in Latin American history. Over the last four years, Brazilians have experienced near weekly police operations and arrests of the elite, from top politicians to businessmen like former Odebrecht CEO Marcelo Odebrecht.

Investigators uncovered a major scheme in which construction companies essentially formed a cartel that doled out inflated contracts from state oil company Petrobras, paying billions in kickbacks to politicians and businessmen.

While Moro, who oversees many cases in the so-Called "Operation Car Wash," is hailed as a hero by many, others see him as a partisan hit man out to get da Silva and the Workers' Party.

Still, the list of investigation targets include people across the spectrum, including President Michel Temer.

Da Silva was convicted in July of helping a construction company get sweetheart contracts in exchange for the promise of the apartment. He denies any wrongdoing in that case or in several other corruption cases that have yet to be tried. An appeals court upheld the conviction in January and even lengthened the sentence to 12 years and one month.

Workers' Party leaders promised demonstrations, including vigils that would be organized nationwide beginning Friday. Whether the party, weakened after the impeachment and scandals, can mobilize major demonstrations remains to be seen.