CAIRO — Two former Egyptian presidents appeared Wednesday in the same Cairo courtroom, with Hosni Mubarak testifying in a retrial of Mohamed Morsi on charges related to prison breaks at the height of the 2011 uprising that toppled Mr. Mubarak.

Mr. Mubarak, 90, whose nearly three-decade rule was ended by a popular uprising in 2011, entered the courtroom with his two sons, Alaa and Gamal. He carried a cane and wore a dark blue suit and matching tie. He appeared physically well and mentally sharp, though his speech was slow at times. Chief Judge Mohammed Sherin allowed Mr. Mubarak to take a seat while testifying.

The hearing took place amid heavy security in a police facility in a southern Cairo suburb.

[On June 17, 2019, Mr. Morsi died in court.]

Mr. Morsi, 67, and Muslim Brotherhood allies swiftly rose to power in elections after Mr. Mubarak’s ouster, only to find themselves imprisoned a year later when millions protested against them for abuse of power, leading to a military overthrow of the government.