Egypt's former President Mohamed Morsi has died after appearing in court in the capital, Cairo, according to authorities.
The public prosecutor said the 67-year-old collapsed in a defendants' cage in the courtroom and was pronounced dead in hospital at 4:50pm local time (02:50 GMT) on Monday. A medical report showed no apparent recent injuries on his body, the prosecutor said.
"Morsi died today while attending a session in his trial on espionage charges. During the session, he was granted permission to address the judge," a presenter with Egypt's state TV said.
"After the session was adjourned, the former president blacked out and then died. His body was taken to a hospital."
Morsi had a history of health issues, including diabetes and liver and kidney disease. He had suffered from medical neglect during his imprisonment, compounded by the poor conditions in jail.
There have been various reports over the years that Morsi had been mistreated and tortured in jail, with activists saying on Monday his death should be seen in context of the Egyptian authorities' systematic isolation and mistreatment of political detainees.
Human Rights Watch called the news of Morsi's death "terrible" but "entirely predictable", citing the government's "failure to allow him adequate medical care".
"The government of Egypt today bears responsibility for his death, given their failure to provide him with adequate medical care or basic prisoner rights," the group said in a statement to Al Jazeera.
Morsi became Egypt's first democratically elected president in 2012, one year after the Arab Spring uprising saw the end of President Hosni Mubarak's 30-year rule.
He was then deposed in July 2013 following mass protests and a military coup led by Egypt's current President Abdel Fattah el-Sisi, and was immediately arrested.