Egypt’s first democratically elected president, Islamist leader Mohammed Morsi, has been buried a day after his collapse and death inside a Cairo courtroom.

Mr Morsi’s family attended funeral prayers in the mosque of Cairo’s Tora prison, followed by the burial at a cemetery in the city’s western district of Nasr City, said Abdul-Moneim Abdel-Maqsoud, a member of his defence team.

Mr Morsi’s son, Ahmed, said security agencies refused to allow Mr Morsi to be buried at the family’s cemetery in his hometown in Sharqia province, and instead had him interred at a Cairo cemetery dedicated to prominent Islamists.

Mohammed Morsi
Mr Morsi was caged during many of his latter court appearances (AP Photo/Ahmed Omar, File)

Security agents turned reporters away from the cemetery, banning them from taking photographs of the funeral. Reporters were also barred from travelling to Mr Morsi’s hometown.

Mr Morsi, 67, hailed from Egypt’s largest Islamist group, the now outlawed Muslim Brotherhood, and was elected president in 2012 in the country’s first free elections following the ousting the year before of long-time leader Hosni Mubarak.

The military toppled Mr Morsi in 2013 after massive protests and crushed the Brotherhood in a major crackdown, arresting Mr Morsi and many others of the group’s leaders.

During his years in prison, Mr Morsi, who was known to have diabetes, was often held in solitary confinement and was largely barred from receiving visitors. His family was only allowed to visit three times. While in detention, Mr Morsi continued to appear in court on a range of charges.

In early court sessions he gave angry speeches until judges ordered him to be kept in a glass cage where they could turn off his audio.

The Brotherhood has accused the government of “assassinating” him through years of poor prison conditions. The group demanded an international investigation into Mr Morsi’s death and called on Egyptians to protest outside Egyptian embassies across the world.

Egypt’s chief prosecutor said Mr Morsi’s body would be examined to determine the cause of his death. State TV, citing an unnamed medical source, said he died after suffering a heart attack.

Mr Morsi collapsed just after he had addressed the court, speaking from inside the glass cage and warning that he had “many secrets” he could reveal, a judicial official said.

In his final comments, he continued to insist he was Egypt’s legitimate president, demanding a special tribunal, one of his defence lawyers, Kamel Madour told The Associated Press. State TV said Mr Morsi died before he could be taken to hospital.