A Brazilian judge on Monday ordered the immediate release of ex-president Michel Temer, days after the former leader was detained on allegations of being the leader of a “criminal organisation.”

Temer, who was arrested Thursday in Sao Paulo and transferred to Rio de Janeiro, is the second ex-president of the Latin American country to be caught up in a sprawling, years-long anti-corruption probe called Car Wash that has claimed scores of political and corporate scalps.

The preventative detention of the 78-year-old predecessor of the current far-right President Jair Bolsonaro had no legal justification, judge Antonio Ivan Athie said in the ruling.

Athie extended the release order to former mines and energy minister Moreira Franco, who was also arrested along with several other people.

“I am not against the so-called Car Wash (investigation),” Athie said in his decision.

“I want to see our country free from the corruption that plagues it. However, without consitutional guarantees, guaranteed to all … there is no legitimacy in the fight against this plague.”

The federal prosecutor’s office said Thursday that the investigation into Temer had uncovered “the existence of a criminal organization in full operation, involved in concrete acts of clear gravity,”.

It described a “sophisticated criminal system” which by the end of 2014 had made illicit payments of some one million reais (the equivalent of $500,000 at the time) in connection with the construction of a nuclear power plant that was never completed.

Investigations suggest the group may have committed “various crimes” with public agencies and state-owned companies involving nearly half a billion dollars, the statement said.

Temer, Brazil’s most unpopular leader ever, faced several corruption accusations on leaving office last year.

Brazil’s Congress voted to dismiss two allegations in 2017, cementing his reputation as the ultimate survivor in one of the world’s messiest and scandal-ridden democracies.

A third accusation was filed days before Bolsonaro’s mandate started on January 1, leaving Congress no time to evaluate the charge.

Starting as an investigation into money laundering at a car wash in the capital Brasilia in 2014, the probe expanded to uncover a vast graft operation involving state oil firm Petrobras and major construction companies and bribes to politicians of several parties.

More than 150 people have been convicted and hundreds more charged. The scale of the corruption uncovered has stunned Brazilians weary of graft among their leaders.