Mohamed Morsi was Egypt's first democratically elected president.

Former Egyptian president Mohamed Morsi died on Monday in a Cairo hospital after fainting during a session in court, judicial and security sources said.

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

Turkish President Recep Tayyip Erdogan, a strong ally of the Islamist president during his brief tenure as Egypt's leader, paid tribute to Morsi and called him a "martyr".

The official Al-Ahram news website also reported the death of Morsi, 67, who was Egypt's first democratically elected president but spent just one turbulent year in office after the 2011 uprising before the army toppled him in 2013.

The Islamist leader has been in prison since his ouster 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.

Since his overthrow on July 3, 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.

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

Morsi's turbulent rule was marked by deep divisions in Egyptian society, a crippling economic crisis and often-deadly opposition protests.