Brazil's Supreme Federal Court (STF) justices voted to reject former President Luiz Inacio Lula da Silva's plea to avoid prison in the early hours of Thursday.
Lula's defeat was a narrow one, with six votes to deny the habeas corpus and five to grant it, after over 10 hours of session. The decisive vote against the plea was given by Court President Carmen Lucia Rocha.
With the habeas corpus denied, Lula can be arrested at any time, which will prevent him from participating in this year's presidential elections.
Lula is facing a controversial accusation of corruption and money laundering, in a case involving an apartment which he is accused of having received as a bribe for favoring companies in governmental contracts.
Lula repeatedly denied owning the apartment.
His defense team said that the prosecution did not manage to present evidence that Lula owns the apartment, since there exist no contracts with his name, no documents attesting the ownership, and nothing more than the testimony of defendants who provided evidence in exchange for leniency.
In January, Brazil's Workers' Party (PT) declared that its founder and former president Lula will be its candidate again in the October's election.
In previous polls on preferred candidates for the election, Lula enjoyed a clear lead over his potential rivals. Without him on the run, the election is quite unpredictable.