Egypt's first democratically elected president Mohamed Morsi was buried on Tuesday, as the UN backed calls for an independent investigation into the causes of his death after he collapsed in a Cairo courtroom.
The Islamist leader, who was overthrown in 2013 after a year of divisive rule and later charged with espionage, was buried at a cemetery in eastern Cairo's Medinat Nasr, one of his lawyers said.
Abdel Moneim Abdel Maksoud said family members had washed Morsi's body and prayed the last rites early on Tuesday morning at the Leeman Tora Hospital.
That lies near the prison where Egypt's first civilian president, a prominent Muslim Brotherhood member, had been held for six years in solitary confinement and deteriorating health.
The prosecutor general's office said the 67-year-old leader had collapsed and "died as he attended a hearing" on Monday over alleged collaboration with foreign powers and militant groups.
Abdel Maksoud told AFP that only around 10 family members and close Morsi confidants were present at the funeral, including himself.
An AFP reporter saw a handful of mourners entering the cemetery complex, accompanied by police officers, but journalists were prevented from entering the site.
The graveyard is in the same suburb as the largest massacre in Egypt's modern history, the August 2013 crackdown on Islamist sit-ins at two Cairo squares, weeks after Morsi's ouster by the military.
Over 800 people were killed in a single day as security forces moved against protesters demanding Morsi's reinstatement.
The attorney general's office said Morsi, who appeared "animated", had addressed the court on Monday for five minutes before falling to the ground inside the defendants' glass cage.
Another of Morsi's lawyers, Osama El Helw, said other defendants had started banging on the glass, "screaming loudly that Morsi had died".
The attorney general said Morsi had been "transported immediately to the hospital", where medics pronounced him dead - a version of events backed up by a judicial source.
Since Morsi's overthrow on July 3, 2013, his former defence minister, now President Abdel Fattah al-Sisi, has waged an ongoing crackdown that has seen thousands of Muslim Brotherhood supporters jailed and hundreds facing death sentences.
The United Nations human rights office called on Tuesday for an independent probe into Morsi's death while in state custody.
"Any sudden death in custody must be followed by a prompt, impartial, thorough and transparent investigation carried out by an independent body to clarify the cause of death," said Rupert Colville, spokesman for the United Nations High Commissioner for Human Rights.
He said Morsi "also appears to have been held in prolonged solitary confinement", and that the investigation must "encompass all aspects of the authorities' treatment of Mr. Morsi to examine whether the conditions of his detention had an impact on his death".
The Brotherhood's political wing - the Freedom and Justice Party - accused Egyptian authorities of "deliberately killing him slowly" in solitary confinement.
"They withheld medication," it said in a statement. "They did not grant him the most basic human rights."
The Egyptian government has not officially commented on his death.
Morsi's death was barely mentioned in local press, which referred to him by his full name but not his position as former president.
Morsi last saw his family in September 2018. A month later, one of his sons, Abdallah, was arrested.
Abdel Maksoud was the last member of his defence team to see him, in November 2017.
Rights group Amnesty International also urged Egyptian authorities to open "an impartial, thorough and transparent investigation" into his death, while Human Rights Watch said Morsi had suffered years of "insufficient access to medical care".
A group of British parliamentarians in March 2018 warned that his detention conditions, particularly inadequate treatment for his diabetes and liver disease, could trigger his "premature death".
"Sadly, we have been proved right," said Crispin Blunt, the MP who chaired the committee, in a statement on Tuesday.
Allies such as Qatar and Turkey, widely seen as backing the Muslim Brotherhood, paid tribute to Morsi, as well as the Syrian opposition which he supported against President Bashar al-Assad.
In Turkey, thousands joined in prayers for him in Istanbul's Fatih mosque on Tuesday.
President Recep Tayyip Erdogan called Morsi a "martyr" and blamed Egypt's "tyrants" for his death.
But in his homeland, Morsi has a chequered legacy.
He spent a turbulent year in office before being toppled by the military following millions-strong protests demanding his resignation.
He has been in prison since his ouster, facing trial on charges including spying for Iran, Qatar and militant groups such as Hamas.
Morsi was sentenced to death in May 2015 for his role in jailbreaks during the uprising four years earlier that ousted longtime president Hosni Mubarak. He appealed and was being retried.
His death comes days before Egypt hosts the Africa Cup of Nations football tournament, starting Friday.
An official from the Confederation of African Football said the security situation had not been affected by Morsi's death, and that the tournament would go ahead as planned.