Egypt's first democratically elected president Mohamed Morsi, an Islamist who was ousted after one year of divisive rule, died after collapsing in court on Monday, the attorney general said. He was 67.
Amnesty International called for an independent probe into the circumstances in which he died, while state TV said his death was due to a cardiac arrest.
Morsi, also the country's first civilian president, had appeared "animated" during a hearing in the retrial of an espionage case in which he was accused of collaborating with foreign powers and militant groups, judicial and security sources said.
"The court granted him his request to speak for five minutes… He fell to the ground in the cage… and was transported immediately to the hospital. A medical report found… no pulse or breathing," said the attorney general's office.
"He arrived at the hospital dead at 4:50 pm exactly and there were no new, visible injuries found on the body."
One of Morsi's legal defence team described the moment he received news of his death.
"We heard the banging on the glass cage from the rest of the other inmates and them screaming loudly that Morsi had died," the lawyer, Osama El Helw, told AFP.
Since Morsi's overthrow on July 3, 2013, his former defence minister, now President Abdel Fattah al-Sisi, has waged an ongoing crackdown, targeting his supporters from the Muslim Brotherhood with thousands jailed and hundreds facing death sentences.
A judicial source said Morsi had fainted during a break in the trial hearing.
The court officials "had just finished the session for the espionage case and they informed the judge that he had fainted and needed to be transported to a hospital where he later died", he told AFP.
Abdel Moneim Abdel Maksoud, another of Morsi's lawyers, said Morsi would be buried in the district of Medinat Nasr in eastern Cairo but was unable to say when the funeral would be held.
Morsi last saw his family in September 2018 and a month later one of his sons, Abdallah, was arrested.
Abdel Maksoud was the last member of his defence team to see the former Islamist president, back in November 2017.
The Brotherhood's political wing – the Freedom and Justice Party – accused Egyptian authorities of "deliberately killing him slowly".
They "put him in solitary confinement… they withheld medication and gave him disgusting food… they did not grant him the most basic human rights," it said in a statement.
International rights group Amnesty International called on Egyptian authorities to open a probe into Morsi's death.
"The Egyptian authorities must immediately order an impartial, thorough and transparent investigation into the circumstances of his death, as well as his detention conditions and his ability to access medical care," the group said.
Turkish President Recep Tayyip Erdogan, a strong ally of Morsi during his brief tenure as Egypt's leader, paid tribute to the "martyr".
The Palestinian Islamist movement Hamas also hailed Morsi's influence.
Internationally he may have received some support but in his homeland, Morsi has a chequered legacy.
Following the news of his death, Egyptian television channels went into feverish overdrive labelling the Brotherhood a "terrorist group" and playing a looping tagline of "The Brothers are liars".
Morsi spent just one turbulent year in office after the 2011 uprising. He was toppled in a military overthrow after millions took to the streets demanding his resignation.
The Islamist leader has been in prison since his ouster on trial for several cases including for spying for Iran, Qatar and militant groups such as Hamas in the Gaza Strip.
Morsi was also accused of plotting terrorist acts.
He was sentenced to death in May 2015 for his role in jailbreaks during the uprising that ousted his predecessor, longtime autocrat Hosni Mubarak.
A group of British parliamentarians in March 2018 warned in a report that his detention conditions had not met international standards and could lead to his "premature death". Other Brotherhood leaders have also died in custody.
The years following Morsi's overthrow have seen a surge in bombings and shootings targeting security forces, particularly in the restive northern Sinai Peninsula, a stronghold of the Islamic State group.
Morsi's turbulent rule was marked by deep divisions in Egyptian society, a crippling economic crisis and often-deadly opposition protests.
His death comes only days before Egypt is set to host the Africa Cup of Nations football tournament from Friday.
Authorities have been on high alert for any security breaches noting in an interior ministry Facebook post published Wednesday that thousands of forces would be deployed to secure venues.