CAIRO (Reuters) - A Cairo court sentenced 18 defendants on Sunday to two years in prison for insulting the judiciary, after the defendants cheered inside the cage when one of them threw his shoe at the judge, security sources and a lawyer said.

Amar El Shahat, a 19-year-old student, turned around and aimed his shoe at the head of the court as he was being sent back to the cage after being questioned before the court for making noise inside the cage, a police official who was in the courtroom said.

El-shahat is being tried along with 22 others on terrorism charges and possessing weapons, with five being tried in absentia. The trial that began in 2015 was taking place in the police academy.

Sunday’s sentence was for a separate charge of insulting the judiciary during a court hearing.

A policeman who was standing behind the Mohammed Shereen Fahmy, the judge, caught the shoe just before it could hit Fahmy’s head, said Khaled el Masry, a lawyer representing three of the defendants, who was in the courtroom.

The rest of the defendants supported their colleague, which is what led the court to move a criminal case against them, and accuse them of insulting the judiciary, the police official said. They were all sentenced to two years in prison after a representative of the general prosecution in court called for them to be handed the maximum sentence, the police official added.

The defendants have the right to appeal against the decision, but El Masry said they had been handed two years in prison in a previous court session but didn’t appeal. “They do not recognize the court as a valid judicial body that could try them,” el Masry said.

The army forced Mursi, the country’s first freely-elected president from power in 2013 following mass protests against his rule. It then launched a crackdown against his organization, arresting thousands on accusations of violence and terrorism.

The Muslim Brotherhood was labeled a terrorist organization last year and most of its senior leaders are in prison awaiting trial on charges relating to violence and terrorism.