The 78-year-old predecessor of current far-right President Jair Bolosonaro was accused of money laundering scheme.
Brazil's ex-president Michel Temer was free from jail on Monday as the judge said there were no legal grounds for his detention.
The 78-year-old predecessor of current far-right President Jair Bolsonaro was accused of money laundering scheme. He was arrested on March 21 in Sao Paulo becoming the latest the second ex-president of the Latin American country to be caught up in an anti-corruption probe called Car Wash.
Launched in 2014, the Car Wash investigation uncovered a vast graft operation involving state oil firm Petrobras and major construction companies and bribes to politicians of several parties.
Former mines and energy minister Moreira Franco and other detained with Temer were also released.
"I am not against the so-called Car Wash (investigation)," judge Antonio Ivan Athie said in his decision.
"I want to see our country free from the corruption that plagues it. However, without constitutional guarantees, guaranteed to all ... there is no legitimacy in the fight against this plague," Athie added.
Despite evidence that could incriminate the accused, it "did not justify preventative detention", Athie said, pointing to the absence of proof that the accused were a threat to public order or would hide evidence.
Hours after the decision was taken, Temer left the jail and went in a car. The federal prosecutor's office said it would appeal the decision.