Egypt's former President Mohammed Morsi collapsed moments after addressing the court in Cairo, officials said. Morsi, who was 67, had been in custody since his removal after mass protests.
Morsi spoke for about five minutes from a soundproof glass cage at a hearing on charges of espionage when he collapsed. He was pronounced dead in hospital at 16:50 local time. State TV said the cause of death was a heart attack.
The Muslim Brotherhood said the death was a "full-fledged murder".
According to BBC News, activists and his family had long said Morsi was not receiving treatment for serious health problems such as high blood pressure and diabetes, and was constantly being held in solitary confinement.
Last month, his family said authorities had repeatedly denied access to him and that they knew little about the state of his health. During his time in prison, Morsi was allowed only three visits from relatives and was denied access to his lawyers or a doctor, according to human rights group Amnesty International, reported BBC News.
Turkey's President Recep Tayyip Erdogan has been quick to describe him as a martyr.
According to BBC News, last year, a British parliamentary panel reported he was being kept in solitary confinement for 23 hours a day, which they concluded could be classified as torture. They warned this could lead to premature death.
Freedom and Justice party, said Morsi's death amounted to an "assassination", and urged supporters to gather at the funeral and demonstrate outside Egyptian embassies around the world.
"They placed him in [solitary] confinement throughout his detention which exceeded five years, prevented medicine and provided poor food... They prevented doctors and lawyers and even communicating with his family. They deprived him from the simplest human rights."
Crispin Blunt MP, who led a panel of British MPs who had warned about Morsi's health, called for a "reputable independent international investigation", and said Egypt's government had a "duty to explain his unfortunate death".
Amnesty's deputy director for the Middle East and North Africa Magdalena Mughrabi said: "[Morsi] was held in solitary confinement for almost six years, placing a considerable strain on his mental and physical wellbeing... [H]e was effectively cut off from the outside world."
Human Rights Watch Middle East director Sarah Leah Whitson said Morsi's death was "terrible but entirely predictable".
Morsi studied Engineering at Cairo University in the 1970s before moving to the US to complete a PhD.
He was chosen as the Muslim Brotherhood's presidential candidate for the 2012 election.
According to BBC News, anti-government protesters took to the streets across Egypt to mark the first anniversary of the day he took office, on 30 June 2013.
Three days later, the army suspended the constitution, announced an interim government ahead of new elections and detained Morsi, who denounced the move as a coup. Abdul Fattah al-Sisi, then army chief, was elected president in 2014 and re-elected last year in polls rights groups called "farcical".
After Abdul Fattah al-Sisi’s takeover of the government, authorities launched a crackdown on Morsi’s supporters and other dissent, and hundreds of people have been killed and tens of thousands others detained in conditions often described as being in violation of their human rights.
His son Abdullah told the Reuters news agency he did not know the location of the body and that authorities were refusing to allow Morsi to be buried in his native Nile Delta province of Sharqiya, reported BBC News.