Egypt’s first democratically elected civilian president, Mohamed Morsi, has collapsed during a court session and died, almost six years after he was forced from power in a bloody coup.

Morsi, a senior figure in the now-banned Muslim Brotherhood, was attending a session in his trial on espionage charges on Monday when he blacked out and died, according to state media.

“After the case was adjourned, he fainted and died. His body was then transferred to the hospital,” reported the Egyptian state newspaper al-Ahram, referring to Morsi’s retrial for allegedly spying for the Palestinian Islamist organisation Hamas.

Egypt’s public prosecutor said Morsi, 67, was pronounced dead on arrival at a Cairo hospital, after he fainted inside the defendants “cage” in the courtroom. Nabil Sadiq’s statement said the cause of death was being investigated but that “there were no visible, recent external injuries on the body of the deceased”.

The Brotherhood accused the government of “assassinating” Morsi through years of poor prison conditions, and called on Egyptians to gather for a mass funeral.

“We heard the banging on the glass cage from the rest of the other inmates and them screaming loudly that Morsi had died,” Morsi’s lawyer, Osama El Helw, told AFP.

Turkey’s president, Recep Tayyip Erdoğan, reacted angrily to news of Morsi’s death. “History will never forget those tyrants who led to his death by putting him in jail and threatening him with execution,” he said in a televised speech.

Morsi became president in 2012, following Egypt’s first and only free elections after the dictator Hosni Mubarak was forced from power. He won 51.7% of the vote and his rule marked the peak of power for Egypt’s Muslim Brotherhood, which had functioned for decades as an underground political organisation.

But his time in power was cut short a year later as demonstrators once again took to the streets – this time to protest against Morsi’s rule and demand fresh elections. Egypt’s military seized power in a coup on 3 July 2013, bringing the then defence minister, Abdel-Fatah al-Sisi, to power.

Morsi, right, and Abdel-Fatah al-Sisi at the presidential palace in Cairo in 2012. Photograph: AFP/Getty Images

As president, Sisi has overseen an extensive crackdown on the Muslim Brotherhood and anyone suspected of supporting the group, which Egypt now considers a terrorist organisation.

Morsi was arrested after the 2013 coup and has faced trial on three separate counts of leaking state secrets to Qatar, killing protesters during a sit-in outside the presidential palace, and spying for Hamas.

He received multiple long sentences, including a life sentence for spying for Qatar and a 20-year sentence for killing protesters. A death sentence for charges relating to a mass jailbreak during the revolution was overturned in a retrial in November 2016.

Morsi was subject to retrials in several cases, and was sentenced to a further two years in prison and fined 2 million Egyptian pounds (£83,000) in 2017 for insulting the judiciary.

Many of his supporters met an even worse fate. On 14 August 2013, Egyptian security forces raided two protest encampments that had been set up in Cairo to demand that Morsi be reinstated. At least 1,150 were killed in five separate incidents when Egyptian forces opened fire on protesters, according to Human Rights Watch.

The former president, who had a history of ill health including diabetes and liver and kidney disease, was held in solitary confinement in Tora prison in Cairo.

In 2018, a panel of three British parliamentarians reported that Morsi was being kept in solitary confinement for 23 hours a day, with just one hour allowed for exercise.

Crispin Blunt, who led the UK group, called on Monday for an investigation into Morsi’s death. “The Egyptian government has a duty to explain his unfortunate death and there must be proper accountability for his treatment in custody,” he said.

Morsi’s supporters said his death was not a surprise. “We had been expecting the worst for some time,” said Wael Haddara, a former adviser, speaking from Canada.

“In many ways, this was the expected result of the military’s actions,” he said. “But he was a friend, and a symbol for many Egyptians, so it’s painful.”