Former Brazilian president Luiz Inacio Lula da Silva has been taken into police custody after a tense showdown with his own supporters.

It comes after an intense three days that underscored raw emotions over the incarceration of a once wildly popular leader who has been engulfed by corruption allegations.

Just hours earlier, Lula told thousands of supporters that he would turn himself in to police, but also maintained his innocence and argued his corruption conviction was simply a way for enemies to make sure he does not run - and possibly win - re-election in October.

When he first tried to leave to turn himself in, however, dozens of supporters blocked a gate where a car carrying Lula was trying to exit.

"Surround, surround (the building) and don't let them arrest him," chanted supporters. After a few minutes of tense words between guards and supporters, the former president got out of the car and entered the metal workers union headquarters where he had been holed up.

Police vehicles surrounded the union that was the birthplace of Lula's rise to power, raising the fears of clashes. Lula emerged a second time shortly after nightfall, this time surrounded by bodyguards who pushed back scores of supporters who tried to stop his advance.

The dramatic scene was the latest development in a whirlwind series of days, which began when the Supreme Federal Tribunal, the country's top court, ruled against his petition on Thursday to remain free while he continued to appeal his conviction.

Judge Sergio Moro, who oversees many of the so-called "Car Wash" cases, then ordered an arrest warrant for Lula, giving him until 5pm on Friday to present himself to police in Curitiba, about 260 miles south-west of Sao Bernardo do Campo, and begin serving his 12-year sentence.

Lula did no such thing. Instead, he hunkered down with supporters in the union headquarters.

"The police and 'Car Wash' investigators lied. The prosecutors lied," said Lula, as a few thousand supporters cheered.

"I don't forgive them for giving society the idea that I am a thief," he continued.

Still, Lula said he would turn himself in "to go there and face them eye to eye. The more days they leave me (in jail), the more Lulas will be born in this country."

While Lula spoke, some people cried while others chanted "Free Lula!" When he finished speaking, a sea of supporters carried him on their shoulders back into the building.

Mauricio Santoro, a political science professor at the State University of Rio de Janeiro, said that by not complying with the order on Friday, Lula "wanted to demonstrate strength and popularity, showing that he is a political leader capable of gathering a crowd in his support."

Choosing the metal workers union to take refuge, and not the Workers' Party headquarters, was also significant, said Mr Santoro.

"It shows that he wants to emphasise his trajectory as leader of a social movement, rather than his role as leader of a party marked by allegations of corruption," he said.

Last year, Moro convicted Lula 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 former president has always denied wrongdoing in that case and in several other corruption cases that have yet to be tried.

Still, his jailing marks a colossal fall from grace for a man who rose from poverty to power against steep odds in one of the world's most unequal countries.

Born in the hardscrabble northeast, Lula rose through the ranks of the union in the country's industrial south. In 1980, during the military dictatorship, he was arrested in Sao Bernardo do Campo for organizing strikes. He would spend more than a month in jail.

After running for president several times, in 2002 Lula finally won. He governed from 2003 to 2010, leaving office an international celebrity and with approval ratings in the high 80s.

Former US president Barack Obama once called Lula the "most popular politician on Earth".

Workers' Party leaders insist that Lula, 72, will still be the party's candidate in October. Technically, being jailed does not keep him off the ballot.

In August, however, the country's top electoral court makes final decisions about candidacies. It is expected to deny Lula's candidacy under Brazil's "clean slate" law, which disqualifies people who have had criminal convictions upheld. Lula could appeal such a decision, though doing so from jail would be more complicated.