Mohammed Morsi, the first democratically-elected president of Egypt who was then ousted in a 2013 military coup, collapsed and died in court on Monday, according to Egyptian state media.
Mr Morsi, 67, had been imprisoned since he was overthrown and reportedly fell over during a court appearance in one of several long-running prosecutions against him.
“He was speaking before the judge for 20 minutes then became very animated and fainted. He was quickly rushed to the hospital where he later died,” a judicial source said.
Human rights groups said Mr Morsi had been given poor medical treatment by Egyptian authorities during his six years in prison, much of it in solitary confinement, which potentially contributed to his death.
Mr Morsi, a leader of the Muslim Brotherhood, came to power in 2012 in the first free elections in Egypt after the country’s 2011 Arab Spring revolution, which forced long-time leader Hosni Mubarak from power.
His time in office was a chaotic period in post-revolution Egypt and Mr Morsi alarmed many Egyptians and the international community with a declaration giving himself and his Islamist parliamentary allies sweeping powers.
Millions of people took to the streets in June 2013 to protest against him and the Egyptian military used the vast demonstrations as a pretext to launch a military coup and overthrow Mr Morsi.
A group of Egyptian generals, led by then-defence minister Abdel Fattah el-Sisi, swept Mr Morsi from office and took power for themselves.
In August 2013, the Egyptian military killed more a thousand of Mr Morsi’s supporters as they protested against the coup. The shootings, among the worst mass killings carried out by a government against protesters since Tiananmen Square, came to be known as the Rabaa Massacre.
Today, Mr Sisi is himself president and has presided over a sweeping crackdown on political opposition and the free media. Critics have accused him of imposing a far more authoritarian regime than that of Mr Mubarak.
Mr Sisi recently forced through changes in the constitution to allow himself to stay in office until 2030.
Mr Morsi was jailed immediately after the coup and charged with killing protesters and passing intelligence to Qatar. He was sentenced to death on espionage charges in 2016 although a court later overturned the sentence.
Sarah Leah Whitson, Middle East director for Human Rights Watch said Mr Morsi had been treated poorly by Egyptian authorities during his six years in prison.
“This is terrible but entirely predictable, given government’s failure to allow him adequate medical care, much less family visits,” she said.
Mr Morsi became a symbol to many of his fellow Islamists as a former president trapped inside a courtroom cage and forced to wear a prison jumpsuit.
“May Allah rest our Morsi brother, our martyr’s soul in peace,” said Recep Tayyip Erdogan, the president of Turkey who follows Islamist ideology.
Egyptian security forces are likely to be put on high alert to prevent Islamists from using Mr Morsi’s death as a rallying cry.
The Muslim Brotherhood has been outlawed in Egypt and Mr Sisi’s forces have hunted down many of its leaders and sympathisers, while falsely accusing other political opponents of being Islamists.