CAIRO — Six years after roaring crowds ousted him at the peak of the Arab Spring, former President Hosni Mubarak of Egypt was freed early Friday from the Cairo hospital where he had been detained, capping a long and largely fruitless effort to hold him accountable for human rights abuses and endemic corruption during his three decades of rule.

Mr. Mubarak, 88, was taken under armed escort from the Maadi Military Hospital in southern Cairo, where he had been living under guard in a room with a view of the Nile, to his mansion in the upmarket suburb of Heliopolis.

“He went home at 8:30 this morning,” his longtime lawyer, Farid el-Deeb, who has stewarded Mr. Mubarak through a tangled cluster of prosecutions since 2011, said by telephone. Mr. Mubarak celebrated his release by having breakfast with his wife, Suzanne, and sons, Alaa and Gamal.

The release begins a third act for Mr. Mubarak, a once unassailable Arab ruler and American ally who came to power in 1981 after the assassination of President Anwar Sadat during a military parade. Thirty years later, Mr. Mubarak’s own rule ended abruptly as multitudes thronged Tahrir Square for 18 days in the heady, hopeful early months of the Arab Spring.