CAIRO — Egypt’s top appeals court cleared former President Hosni Mubarak of any responsibility for the killing of hundreds of people during the 2011 protests that ended his 30-year rule, sweeping away the final legal hurdle to Mr. Mubarak’s release from detention.

The ruling drew cheers from Mr. Mubarak’s supporters, who have in recent years cast off the stigma once associated with his name to air increasingly vocal demands for his release. But it represented a bitter landmark for the millions of Egyptians who risked their lives to oust Mr. Mubarak and his circle during the heady, 18-day uprising in early 2011.

None of the Mubarak-era figures who grew rich and influential during his time in power are still in jail. The sole exception is Mr. Mubarak himself, who has been under guard for years at the Maadi Military Hospital in Cairo, at a room overlooking the Nile.

But the decision to keep him in detention is widely seen here as a political matter rather than a legal one — constructed to avoid any embarrassment to Egypt’s current leader, President Abdel Fattah el-Sisi, who sometimes praises the 2011 revolution.