CAIRO (AFP) - An Egyptian court dismissed on Saturday a murder charge against ousted president Hosni Mubarak over the deaths of protesters during a 2011 uprising that ended the former strongman's decades-long rule.
The court also acquitted Mubarak of a corruption charge, but he will remain in prison because he is serving a three-year sentence in a separate corruption case.
Seven of his security commanders, including the feared former interior minister Habib al-Adly, were acquitted over the demonstrators' deaths.
Corruption charges against the sons, Alaa and Gamal, were also dropped.
Cheers broke out in the courtroom and Mubarak's two sons and co-defendants stooped down to kiss his forehead when the judge read out the verdict, as Mubarak lay in an upright stretcher inside the caged dock.
Judge Mahmud Kamel al-Rashidi said the commanders, including Adly, were "innocent".
The ruling came after a dramatic retrial in which the former president defended his 30-year rule.
An appeals court overturned an initial life sentence for Mubarak in 2012 on a technicality.
Earlier, the 86-year-old arrived in court wheeled into the caged dock on an upright stretcher, dressed in his trademark shades and wearing the blue clothes of a convict.
He was flown to the court in a Cairo suburb by helicopter from a military hospital.
The usually stone-faced Mubarak, wearing his trademark shades, allowed himself a faint smile.
He was later transported back to a Cairo military hospital where he is serving his sentence, appearing in a wheelchair from a balcony door to wave at supporters gathered at the gates.
His lawyer Farid al-Deeb told AFP that the verdict was "a good ruling that proved the integrity of Mubarak's era". An appeals court had overturned an initial life sentence for Mubarak in 2012 on a technicality. Saturday's verdict may also be appealed.
Many Egyptians increasingly look to the former autocrat's stable era with nostalgia in light of the turmoil that followed his overthrow.
His successor Mohamed Mursi, a leader of the main Islamist opposition group under Mubarak, was toppled by the army himself in 2012 following massive protests.
Mubarak's supporters leapt out of their benches in celebration when the judge pronounced the verdict, chanting: "Say the truth, don't be scared - Mubarak is innocent." Some rushed over to his lawyer to congratulate him.
The ruling came after a retrial lasting more than a year in which many witnesses, including Mubarak's former police and intelligence commanders, appeared to exonerate him in their testimony.
Outside the court venue, a sprawling police academy on Cairo's outskirts, relatives of those killed in the revolt were appalled at the verdict.
"It's an oppressive ruling. The blood of my son has been wasted," said Mr Mostafa Morsi, whose son was killed outside a police station during the uprising.
In Cairo's Tahrir Square, the hub of the anti-Mubarak revolt, passers-by were divided on the outcome.
"Justice for the martyrs has been lost," said one woman in her 50s.
Others disagreed. "There is no evidence against Mubarak. He was an honest president," said Mr Mostafa Saed, a retired government worker.
Protesters at the time of the revolt vented years of pent-up fury over police abuses and corruption by attacking and torching stations across the country, leaving the interior ministry on the brink of collapse.
Chief judge Mahmud Kamel al-Rashidi, 63, suggested his ruling was made with a clear conscience as he approached the end of his life.
"God will ask me what did you do in this world, and specifically what did you do as a judge," he told the court before pronouncing his verdict and brandishing a thick copy of the reasoning behind his decision.
He said he dropped the murder charge against Mubarak because the prosecution should not have added him to the case they had initially made against his security chiefs.
During the retrial, Mubarak told the court that he was innocent and praised his own rule, saying it was a time of economic growth.
"The Hosni Mubarak before you would never have ordered the killings of protesters," he said.
Mubarak had pleaded to stay on as president for a few months during the 2011 uprising to oversee the writing of a new Constitution, but the hundreds of thousands of protesters who rallied daily demanded he immediately step down.
Since then, once-banished Mubarak-era officials have made a comeback, using a widespread backlash against former opposition figures blamed for the tumult since the strongman's ouster.
The police force is now feted in the largely pro-government media as it wages a deadly crackdown on pro-Mursi Islamist protesters and militants.
Prime Minister Ibrahim Mahlab was a senior official in Mubarak's now dissolved party, something that would have been unthinkable in the months following the strongman's ouster.
Mubarak's former military intelligence chief Abdel Fattah al-Sisi is now president, having won an election after overthrowing Mursi last year.
Hundreds of members of Morsi's Muslim Brotherhood movement have been sentenced since his downfall.
Mursi himself is standing several trials, including one for taking part in jail breaks and violence during the anti-Mubarak revolt.
The new verdict was initially scheduled for Sept 27, but chief judge Mahmud Kamel al-Rashidi postponed it, saying he had not finished writing the reasoning after a retrial that saw thousands of case files presented.