Egypt's first democratically elected president Mohammed Morsi, an Islamist who was ousted after one year of divisive rule, has died after falling ill during a court hearing, the attorney general said.

Morsi, 67, also the country's first civilian president, had been "animated" during a hearing in the retrial of an espionage case in which he was accused of collaborating with adverse foreign powers and militant groups, judicial and security sources said.

We need your consent to load this rte-player contentWe use rte-player to manage extra content that can set cookies on your device and collect data about your activity. Please review their details and accept them to load the content.Manage Preferences

"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 office of the attorney general.

"He arrived at the hospital dead at 4.50pm 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.

"I saw him from afar wheeled out on the stretcher from the courts complex" from Tora, in southern Cairo, said another one of his lawyers.

Since Morsi's overthrow on 3 July 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.

Following demonstrations in 2011, Mursi became Egypt’s first democratically elected civilian president

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.

Mohammed Mursi last saw his family in September 2018 and a month later one of his sons, Abdallah, was arrested..

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.

Mursi's official Facebook page blamed Egypt's current president with the hashtag "Sisi killed the President".

Turkish President Recep Tayyip Erdogan, a strong ally of Mursi during his brief tenure as Egypt's leader, paid tribute to the "martyr".

Qatar's ruler Sheikh Tamim bin Hamad Al-Thani, another backer of the Islamist, and the Palestinian Islamist movement Hamas also paid tribute.

Turkish President Recep Tayyip Erdogan was a strong ally of Mr Morsi during his brief tenure as Egypt's leader

Hamas said Mursi died "after a long struggle spent in the service of Egypt and its people and primarily the Palestinian cause... in the context of the long struggle with the Zionist enemy."

Internationally he may have received some support but in his homeland Mursi's chequered legacy is still condemned.

Following the news of his death, Egyptian television channels went into overdrive labelling the Brotherhood a "terrorist group" and playing a looping tagline of "The Brothers are liars".

Mohammed Mursi 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 he was ousted, on trial for several cases including for spying for Iran, Qatar and militant groups such as Hamas in the Gaza Strip.

He was also accused of plotting terror 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.

Mr Morsi was toppled in a military overthrow after millions took to the streets demanding his resignation

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

Sarah Leah Whitson, Human Rights Watch Middle East director, tweeted: "This is terrible but ENTIRELY predictable, given government failure to allow him adequate medical care".

Other Brotherhood leaders have also died in custody.

The years following Mursi'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.

Mursi'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 on Wednesday that thousands of forces would be deployed to secure venues.