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.

The 67-year-old Morsi had just addressed the court, speaking from the glass cage he is kept in during sessions and warning that he had "many secrets" he could reveal, a judicial official said. A few minutes afterward, he collapsed, the official said, speaking on condition of anonymity because he was not authorized to talk to the press.

Reports in Egypt say the military and interior ministry announced a state of high alert following the announcement of Morsi's death for fear of riots.

>> Muslim Brotherhood: Terrorist group or political movement? .

State TV said Morsi died before he could be taken to the hospital.

Morsi has been in prison undergoing multiple trials ever since the military ousted him in July 2013 and launched a massive crackdown on his Muslim Brotherhood and other Islamists. 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.

Morsi's son, Ahmed, confirmed the death of his father in a Facebook post.

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.

"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 Egyptian prosecutor has reportedly appointed a special investigation team to look into the circumstances behind Morsi's death.

>> Egypt's first democratically elected president, Mohammed Morsi, has died. Here's why Israel may miss him after all / Archive

Amnesty International urged Egyptian authorities on Monday to investigate former president Morsi's death. "We call on Egyptian authorities to conduct an impartial, thorough and transparent investigation into the circumstances of Morsi's death, including his solitary confinement and isolation from the outside world," Amnesty tweeted in Arabic.

It also called for an investigation into the medical care Morsi was receiving, and for anyone found responsible for mistreatment to be held accountable.

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.

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.

>> Muslim Brotherhood: Terrorist group or political movement? | Analysis

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 sinse.

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 too.

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.

>> Sissi wants West to pay for Egyptian brainpower. But its writers cannot return home | Analysis

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.

State television said Morsi, who was 67, was in court for a hearing on charges of espionage emanating from suspected contacts with the Palestinian Islamist group Hamas.

Morsi was serving a 20-year prison sentence for a conviction arising from the killing of protesters during demonstrations in 2012 and a life sentence for espionage in a case related to the Gulf state of Qatar.

Reuters contributed to this report.