Cairo — Egypt's former president, Mohammed Morsi, the Muslim Brotherhood leader who rose to office in the country's first free elections in 2012 and was ousted a year later by the military, collapsed in court during a trial and died, state TV and his family said. State TV, citing a medical source, said Morsi died from a sudden heart attack, the Reuters news agency reports.

Morsi had been Egypt's elected president following the abdication of Hosni Mubarak in 2011, but was deposed after a military coup in 2013 that installed General Abdel Fattah el-Sisi into power.

Egyptian state TV says the 67-year-old Morsi was attending a court session Monday in his trial on espionage charges when he blacked out and then died before he could be taken to a hospital. Morsi had just addressed the court, speaking from the glass cage he was kept in during sessions and warning that he had "many secrets" he could reveal, a judicial official said.

Then Egyptian President Mohammed Morsi speaks to reporters at the presidential palace in Cairo, July 13, 2012. AP

A few minutes afterward, he collapsed, the official said, speaking on condition of anonymity because he was not authorized to talk to the press. Morsi's son, Ahmed, confirmed the death of his father in a Facebook post.

Get Breaking News Delivered to Your Inbox

Morsi, a leader of Egypt's largest Islamist group, the now outlawed Muslim Brotherhood, was elected president in 2012 in the country's first free elections following the ouster the year before of longtime leader Hosni Mubarak. The military ousted Morsi in 2013 after massive protests and crushed the Brotherhood in a major crackdown, arresting Morsi and many others of the group's leaders. Morsi had been imprisoned since his arrest and was previously sentenced to death for his alleged role in a mass prison break that took place during the 2011 uprising that toppled Mubarak.

Mohammed Sudan, leading member of the Muslim Brotherhood in London, described Morsi's death as "premediated murder" saying that the former president was banned from receiving medicine or visits and there was little information about his health condition. Monday's session was part of a retrial, being held inside Cairo's Tura Prison, on charges of espionage with the Palestinian Hamas militant group.

"He has been placed behind glass cage (during trials). No one can hear him or know what is happening to him. He hasn't received any visits for a months or nearly a year. He complained before that he doesn't get his medicine. This is premediated murder. This is slow death."

The judicial official said Morsi had asked to speak to the court during the session. The judge permitted it, and Morsi gave a speech saying he had "many secrets" that, if he told them, he would be released, but he added that he wasn't telling them because it would harm Egypt's national security. A spokesman for the Interior Ministry did not answer calls seeking comment.

Egypt's deposed president Mohamed Morsi waves from inside the defendants cage during his trial at the police academy in Cairo, Jan. 8, 2015. Getty

Morsi was a longtime senior figure in Egypt's most powerful Islamist group, the Muslim Brotherhood. He was elected in 2012 in the country's first free presidential election, held a year after an Arab Spring uprising ousted Egypt's longtime authoritarian leader Hosni Mubarak. His Muslim Brotherhood also held a majority in parliament.

The military, led by then-Defense Minister Abdel-Fattah el-Sissi, ousted Morsi after massive protests against the Brotherhood's domination of power. El-Sissi was subsequently elected president and has waged a massive crackdown on Islamists and other opponents since.

Since Morsi's ouster, Egypt's government has declared the Brotherhood a terrorist organization and largely crushed it with a heavy crackdown. Tens of thousands of Egyptians have been arrested since 2013, mainly Islamists but secular activists who were behind the 2011 uprising.

He has been sentenced to 20 years after being convicted of ordering Brotherhood members to break up a protest against him, resulting in deaths. An earlier death sentence was overturned. Multiple cases are still pending.

Morsi was held in a special wing in the sprawling Tora detention complex nicknamed Scorpion Prison. Rights groups say its poor conditions fall far below Egyptian and international standards.

Correction: An earlier version of this article stated Hosni Mubarak died in 2012. He abdicated the presidency in 2011 and was sentenced to life in prison in 2012. He was released in 2017 and is alive at age 91.