LIMA (Reuters) - Peru’s top court ruled that ex-President Ollanta Humala and his wife must be freed from jail, where they have been spent the past nine months awaiting trial over money laundering allegations that they deny, the president of the court said on Thursday.

Slideshow ( 2 images )

Ernesto Blume warned that the use of “preventive prison,” or pre-trial detention, must not be overused as the country grapples with its biggest corruption scandal in nearly two decades.

Humala and former first lady Nadine Heredia are two of several politicians, former government officials and business leaders who have been jailed pending trial in connection with Odebrecht, a Brazilian builder that has admitted to paying hundreds of millions of dollars in bribes across Latin America.

“Preventive prison is not the general rule but an exception,” Blume said as he announced the court’s decision. The court “must guarantee the right to personal liberty as well as the presumption of innocence.”

The comments were a rare rebuke of the work of public prosecutors amid widespread outrage over Odebrecht’s bribes, and the ruling could mark a precedent as criminal investigations continue against other former presidents and politicians.

“We have to be very careful.” Blume added. “Media justice is not justice. The only way to strengthen institutions and fight against corruption coherently is by acting constitutionally.”

Former President Alejandro Toledo has been fighting extradition from the United States to serve up to 18 months in preventive prison over allegations he took a $20 million bribe from Odebrecht. Former President Pedro Pablo Kuczynski, who resigned amid mounting graft allegations last month, has been barred from leaving the country while his ties to the company are probed.

Opposition leader Keiko Fujimori and her right-wing party are also under investigation.

Humala, Heredia, Fujimori, Toledo and Kuczynski all deny wrongdoing.

Prosecutors accused Humala and Heredia, who was the leader of Humala’s nationalist party, of taking $3 million in illicit funds from Odebrecht to finance Humala’s 2011 campaign. They argued the couple might flee or obstruct their work unless jailed.

But as Humala and Heredia languished in prison without any formal charges against them, some in Peru argued their jailing was unfair, especially as other political leaders, such as Humala’s former rival Fujimori, remained free.

Blume stressed the court was not weighing in on the accusations against Humala and Heredia and that the couple will have to comply with court-mandated restrictions while investigations continue.

Humala had been sharing a prison with Fujimori’s father, former authoritarian leader Alberto Fujimori, until December, when Kuczynski pardoned Fujimori amid a political crisis.