Brazil's former President Luiz Inacio Lula da Silva waves to supporters in front of the metal workers union headquarters in Sao Bernardo do Campo, Brazil. Picture: Nelson Antoine/AP

Sao Bernardo Do Campo, Brazil - Leftist former president Luiz Inacio Lula da Silva spent the night holed up inside the headquarters of a steel-workers union on Saturday in a standoff with police ordered to arrest him for corruption.

A judge ordered Lula to turn himself in to police on Friday afternoon to start serving a 12-year prison sentence for bribery that will likely end the political career of Brazil's first working-class president and his hopes of returning to power.

The union building in an industrial suburb of Sao Paulo where Lula began his career as a labour leader was surrounded late into the night by thousands of supporters and members of his Workers Party wearing red shirts and waving red flags.

The crowds dissuaded police trying to arrest him after the deadline set by the judge. The police said they would not act during the night to seize Lula as negotiations proceeded on a suitable way to end the standoff.

A source with knowledge of the talks told Reuters that negotiations between Lula and the police "continue and should reach an agreement on Saturday."

The head of the Workers Party, Senator Gleisi Hoffmann, said Lula would take part in a Saturday morning mass at the union headquarters to commemorate the birthday of his late wife Marisa Leticia.

Lula was convicted of taking bribes from an engineering firm in return for help landing government contracts, including a three-floor seaside resort that he denies owning.

His legal team filed a late Friday injunction with the Supreme Court to suspend the prison order, after losing a last-minute plea to the second highest court. The lawyers argued they had not exhausted procedural appeals and painted the case as an effort to remove Lula from the presidential race he is leading.

Under Brazilian electoral law, a candidate is forbidden from running for office for eight years after being found guilty of a crime. Rare exceptions have been made in the past, and the final decision would be made by the top electoral court if and when Lula officially files to be a candidate.

The supporters crowding the streets by the union office cheered defiant speeches calling the case a political witch hunt.

The union where 72-year-old Lula sought refuge served as the launch pad for his career nearly four decades ago, when he led nationwide strikes that helped to end Brazil's 1964-85 military dictatorship.

Lula's everyman style and unvarnished speeches electrified masses and eventually won him two terms as president, from 2003 to 2011, when he oversaw robust economic growth and falling inequality amid a commodities boom.

He left office with a sky-high approval rate of 83 percent and was once called "the most popular politician on Earth" by former U.S. President Barack Obama.