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.
Morsi served just one year of a four-year term, while the organisation to which he belonged, the Muslim Brotherhood, has since been outlawed.
Morsi, who was facing at least six trials, had been behind bars for nearly six years and was serving a 20-year prison sentence for a conviction arising from the killing of protesters during demonstrations in 2012. He was also serving a life sentence for espionage in a case related to the Gulf state of Qatar.
Other charges against the former president included jailbreak, insulting the judiciary and involvement in "terrorism".
His supporters say the charges against him were politically motivated.
In November 2016, the Court of Cassation scrapped the life imprisonment sentence for Morsi and 21 other defendants, including some who had received the death penalty in the same case, and ordered a retrial.
Throughout his imprisonment, Morsi was only allowed three visits from his family.
The first was in November 2013, and the second, which only his wife and daughter were allowed to see him, was in June 2017.
The final visit where his entire family was permitted to see him in the presence of security forces was in September 2018.
Turkish President Recep Tayyip Erdogan was the first world leader to pay tribute to Morsi, calling him a "martyr."
"May Allah rest our brother Morsi, our martyr's soul in peace," said Erdogan, who had forged close ties with late former president.
Denied medical treatment
Last year, a report by three British members of parliament, under the Independent Detention Review Panel, warned that the lack of medical treatment could result in Morsi's "premature death".
"Our conclusions are stark," Crispin Blunt, the panel's chairman, said at the time. "The denial of basic medical treatment to which he is entitled could lead to his premature death."
He added: "The whole overseeing chain of command up to the current president would have responsibility for this."
The members of the panel were denied access by Egyptian authorities to visit Morsi, and relied on testimonies, witness statements, NGO reports and independently submitted evidence.
They said that Morsi was being kept in solitary confinement for 23 hours a day, which under the UN guidelines, would classify as torture.
"Morsi's trial was not put on live TV, he was put on a glass soundproof cage," Al Jazeera's Jamal Elshayyal said.
"He wasn't allow to see his lawyers one-to-one and he wasn't allowed family visits; his family repeatedly complained that aside from the solitary confinement he also wasn't being given the medical treatment he should have," added Elshayyal.
"Therefore, these are the facts that we know. Whatever the state decides to tell us afterwards has to be taken in the context."-Al Jazeera