Egypt’s former president Hosni Mubarak has been sentenced to life in prison after a court convicted him on charges of complicity in the killing of protesters during last year’s uprising that forced him from power.

Habib el-Adly, Mubarak’s minister of the interior, was also jailed for life but Mubarak’s sons Gamal and Alaa were cleared of corruption.

People at the court in Cairo reacted with pleasure at the first sentences and then angrily to the acquittal of Mubarak’s sons and six interior ministry officials and police chiefs. The crowd chanted, “False judgements. The people want to clean the judicial system,” and fights broke out inside and stones were thrown at riot police outside the court.

Mubarak, 84, the first Arab leader to be tried in his own country, remained silent inside a court cage while his once-powerful sons appeared nervous and had dark circles under their eyes. His elder son Alaa whispered verses from the Qur’an.

In sentencing, Judge Ahmed Rifaat Rifaat described Mubarak’s era as “30 years of darkness” and “a darkened nightmare” that ended only when Egyptians rose up to demand change. “They peacefully demanded democracy from rulers who held tight grip on power,” he said.

Rifaat, who was presiding over his last court session before he retires, said Mubarak and Adly did not act to stop the killings during 18 days of mass protests that were met by a deadly crackdown of security forces on unarmed demonstrators. More than 850 protesters were killed in Cairo and other major cities.

Egyptian TV reported that Mubarak would be transferred from the hospital suite where he has been detained to Torah prison in south Cairo but he may have the right to appeal.

It is unlikely the judge’s verdict will put an end to uncertainty and instability in Egypt. Within minutes of the verdict, young men were pulling barricades on to Tahrir Square. The verdict could damage the chance of Ahmed Shafiq, Mubarak’s former prime minister, in the second round of the presidential election on 16-17 June when he runs against the Muslim Brotherhood’s Mohamed Morsi.

Outside there were celebrations, with many chanting “God is greatest”. Soha Saeed, the wife of one of those killed in the uprising that toppled Mubarak on 11 February 2011, shouted: “I’m so happy. I’m so happy.”

Mubarak arrived at the court building by helicopter and was then wheeled into court on a hospital stretcher, wearing sunglasses and looking frail. Protesters outside the building shouted: “Enough talk, we want execution”.

“I want nothing less than the death penalty for Mubarak. Anything less and we will not be silent and the revolution will break out again,” said Hanafi el-Sayed, whose 27-year-old son was killed in the first days of the uprising that erupted in Januarylast year. He had travelled from Alexandria for the trial.

The trial itself has often been plunged in chaotic scenes. Outside the court, Mubarak’s supporters and his opponents have often clashed, hurling stones and abuse at each other.