Egypt's ousted President Muhammad Morsi has died after fainting in a courtroom in Cairo, officials say.
Egypt's public prosecutor said that Morsi collapsed in a court cage after addressing the tribunal on June 17.
Morsi was taken to a hospital where he was pronounced dead, a statement said, adding that a medical report showed no apparent recent injuries on his body.
State television reported that the court hearing was related to charges of espionage emanating from suspected contacts with the Palestinian Islamist group Hamas.
Morsi, 67, was a former top figure in the now-banned Islamist movement Muslim Brotherhood.
He was ousted by the Egyptian military in 2013 following mass protests a year after he took office as the country's first democratically elected leader.
He had remained in custody since then, while the Egyptian authorities launched a crackdown on his supporters.
Human Rights Watch said Morsi’s death was tragic but "predictable" given the authorities' "failure" to allow medical care.
The Muslim Brotherhood accused Egyptian authorities of being responsible for Morsi's "deliberate slow death."
The authorities "put him in solitary confinement... they withheld medication and gave him disgusting food... they did not give him the most basic human rights," a statement said.
Turkish President Recep Tayyip Erdogan, who had forged close ties with Morsi, called him a "martyr" and blamed Egypt's "tyrants" for his death.