If found guilty, the former president could be barred from running for office and even jailed for corruption charges.

Brazil’s Leftist former president Luiz Inacio Lula da Silva called the corruption trial threatening to end his storied career a "farce" during almost five hours of testimony Wednesday.

Arguably the country's most popular and controversial politician, Lula is accused of receiving a seaside apartment as a kickback from the OAS construction company.

If found guilty, he could be barred from running for office and even jailed, destroying his hopes of coming back to power in the 2018 Presidential elections.

The closed hearing put Lula, 71, face-to-face with Judge Sergio Moro, a hero to many Brazilians for his relentless pursuit of senators, millionaires and other powerful figures in a graft probe called "Car Wash."

Lula, whose 2003-2010 rule made him loved by the Left and equally loathed on the right, would be by far Moro's biggest scalp.

However, the fiery orator -- who grew up in severe poverty before becoming a metal workers' union leader, co-founder of the Workers' Party and leftist icon -- was defiant.

"I consider this trial illegitimate and the accusation a farce," he told Moro at the hearing in the southern city of Curitiba, video released afterward showed.

He said prosecutors were accusing him "based on allegations in the press."

As soon as he got out of court, Lula went to a campaign style rally with several thousand supporters who had bused into Curitiba earlier.

"I thought after... there would at least be a document that the apartment was mine," he told them. "I want to be judged on proof."

Lula reiterated his plans to seek a third term next year.

"I am preparing to return as a candidate," he said. "I want to show that the elite is not competent to fix this country but that the steel worker... will manage."

The Lula faithful, many clad in Workers' Party red, responded deliriously, cheering "Lula, warrior of the Brazilian people," and letting off fireworks.

"He still has this incredible charisma, this connection," said lawyer William Bioneck, 30, who was in the crowd.

A much smaller group of opponents also gathered, raising an inflatable caricature of Lula dressed in prison garb.

Embezzlement, bribery

Brazil's media portrayed the court session as a showdown between two of the most powerful men in Brazil.

Moro, 44, has become a national figure for his role leading the "Car Wash" probe, which revealed massive kickbacks to politicians in return for inflated contracts with state oil company Petrobras, much of it during Lula's presidency.

Lula faces a total of five corruption trials.

In Wednesday's case, Lula is alleged to have taken a bribe from OAS -- one of the main Petrobras contractors -- in the form of a seaside apartment at a posh resort near Sao Paulo.

But seated at a table with lawyers and prosecutors, Lula denied everything.

"I never asked for and I never received the apartment," he said.

Prosecutors have previously painted Lula as a kingpin over the wider Petrobras corruption scheme.

However, in the video of the hearing Moro went out of his way to reassure Lula that he would "be treated with maximum respect, as any defendant, but also equally considering the office that he had held previously."

He also stressed that Lula did not face imminent arrest.

Hashtags trending on Twitter reflected the bitter divide over the ex-president's legal problems, including #LulaEuConfio (I trust in Lula) and #MoroOrgulhoBrasileiro (Moro, pride of Brazil).

President Michel Temer, a hugely unpopular figure who took over when Lula's successor Dilma Rousseff was impeached and removed from the presidency last year, appealed for calm.

"We need to calm down the country. The country can't be in this permanent state of conflict, with Brazilian against Brazilian," he said.