Egypt's first freely elected president had suffered from neglect during years of imprisonment after his 2013 overthrow.