An Iraqi court has sentenced to death 24 militants for their role in killing hundreds of soldiers. Four others were acquitted for lack of evidence.

Islamic State (Isis) captured the soldiers when it overran Saddam Hussein’s hometown of Tikrit last summer. They were trying to flee from Camp Speicher, a nearby army base. After Tikrit was captured, Isis posted graphic images and video that showed its gunmen massacring scores of the soldiers after loading the captives on to flatbed trucks and then forcing them to lie face down in a shallow ditch.

All of the defendants pleaded not guilty, insisting they never took part in the massacre. They told the court that their confessions were coerced under torture by Iraqi officers.

At one point, while the chief judge was questioning the militants, several relatives of the dead soldiers stormed the courtroom and started to throw shoes and water bottles at the defendants, who were inside a cage.

After the sentences were passed, the victims’ relatives raised pictures of their loved ones. Some burst into tears and others chanted “Allahu Akbar”, and “oh, Hussein”, in reference to the prophet Muhammad’s grandson, who is revered by Shias.

Ali Abdul-Hamza, whose brother was among the victims, said “justice is done” as he was leaving the courtroom. “We are relieved to see these criminals receiving the maximum punishment,” he said.

Before the trial, the spokesman for Iraq’s supreme judicial council, Abdul-Sattar Bayrkdar, promised that “the trial will be transparent and fair”.

He added that 604 other militants, believed to have taken part in the killing, were still at large.

Following the retaking of Tikrit city four months ago, dozens of people allegedly linked to the massacre were arrested by Iraqi security forces. Iraqi forensic teams immediately began exhuming bodies from mass graves believed to contain some of of soldiers killed by Isis militants.