Hosni Mubarak trial
Egypt's ousted President Hosni Mubarak sits inside a dock at the police academy on the outskirts of Cairo (Reuters)

Deposed Egyptian President Hosni Mubarak is to remain in jail, even though a court has ordered his release.

The Cairo Criminal court ruled that Mubarak, who was deposed in 2011, should no longer be held over alleged responsibility for the deaths of hundreds of protesters.

According to the court, Mubarak has spent the maximum legal time of two years under temporary detention, since he was charged for failing to prevent the killing of 900 anti-regime protesters in the 2011 uprising and should be granted bail.

However the former president, 84, is facing separate new corruption charges for which he is to remain in custody, the court said.

The decision came as the latest twist in Mubarak's protracted legal case.

Sentenced to life imprisonment in 2012, Mubarak was granted a retrial by an appellate court in January this year.

The start of the new proceedings were marked by chaotic scenes, as at the first hearing last week, presiding Judge Mustafa Hassan Abdullah withdrew from the case saying he was "uneasy" about overseeing the retrial. A new judging panel is yet to be appointed.

Mubarak ruled over Egypt for almost three decades, before being toppled at the end of 18 days of unrest in February 2011.

He has been in frail health, going back and forward from prison to a military hospital since his arrest.

During his trial in 2011, and at the last hearing he attended court on a gurney.

Mubarak was said to have suffered from a stroke or to have stomach cancer and also reportedly sustained injuries slipping in the prison bathroom in two separate occasions.