Erbil, Iraq – One afternoon last month, Abu Wahid was told he was going to die.

A former member of the Iraqi police, he cried and read the Quran, but was not surprised about his fate. “I already knew they would kill me,” he said of the Islamic State of Iraq and the Levant (ISIL) fighters who had jailed him.

Abu Wahid, 32, who is from the town of Hawija in northern Iraq, was imprisoned by ISIL fighters eight months ago, after they seized the town in the summer of 2014. He was briefly freed and then arrested again in July. ISIL claimed that Abu Wahid passed secrets about the group’s movements and positions to Kurdish armed groups that control nearby parts of northern Iraq.

The day Abu Wahid was told of his imminent death, the local ISIL judge came to his cell and asked him, “Why have you been giving information about fellow Muslims to the Kurds?” (The vast majority of Kurds in Iraq are indeed Muslim.)

Abu Wahid denied the charge, but he was accused of lying and was kicked. He recalled that the judge told him: “You have to write a will, because tomorrow we will kill you.” Two days earlier, four men in Abu Wahid’s cell had been removed.

VIDEO: Enemy of Enemies: The Rise of ISIL

When men were taken out of the jail “they didn’t come back”, said Abu Wahid, speaking to Al Jazeera from the offices of Kurdish security forces in Erbil. “There was a system, and we were in a queue to be killed.”

The men were taken outside to the back of the jail, which had previously been the house of a judge who fled ISIL’s advance in 2014. Abu Wahid heard the sound of shovels digging a pit behind the wall of the jail. When the men were taken outside, the remaining prisoners could hear the sounds of guns and screaming.

“When they killed one man, the next man would start shouting, ‘Allahu Akbar!’ [‘God is great!’],” said Ahmed Mahmoud, 31, another prisoner accused by ISIL of passing secrets to the Iraqi army.

ISIL subjected the prisoners to torture. During his incarceration, Abu Wahid said he was tortured eight times by his captors, who applied a charge to electric cables attached to his neck.

“First they brought me to a room, sat me down and put water on me. Next they brought electricity cables and applied a charge to my neck. For the next three days, blood would come from my mouth when I slept,” he said. “When I felt dizzy and passed out because I couldn’t take any more, they brought the cables to wake me up again.”

When I felt dizzy and passed out because I couldn't take any more, they brought the cables to wake me up again. Abu Wahid, former ISIL prisoner

After the fifth session, when they threatened to bring his nephew and kill him, Abu Wahid confessed to informing on the ISIL fighters. “After that I started talking,” he said.

After being told of his death sentence, Abu Wahid wrote his will late into the night. “I wrote to [my family] to tell them that tomorrow they will kill me, so take care of your brothers and my sister. When I finished, I rolled up the will … and put it in my pocket,” he said.

Abu Wahid had every reason to worry about the safety of the surviving members of his family. In 2006, armed fighters linked to a predecessor of ISIL beheaded his brother, accusing him of working with the Kurds. A year later, his uncle, a city council member, was murdered, and two of his cousins were on an assassination list. They were accused of working with Sunni tribes opposed to the armed group’s tactics.

At 2am, not long after finishing writing his will, Abu Wahid was startled to hear helicopters and soldiers on the roof.

“Some of my friends were sleeping, so I woke them up and said, ‘There are US soldiers here!'” He then heard the sound of bombs and of Kurdish soldiers shouting: “Don’t be scared – we are here to help!”

They broke down the door to the cell where the startled prisoners were crammed and asked, “Are there any Peshmerga [Kurdish soldiers] here?” When the answer came back in the negative, the prisoners were told to hurry out. “We told them there are files on us in the other room, so they broke down the door and took the files,” Abu Wahid said.

INTERACTIVE: Mapping ISIL’s attacks in 2015

In all, Kurdish and US special forces rescued 69 prisoners, detained six ISIL fighters, and killed 20 more. One US soldier, Master Sergeant Joshua Wheeler, died in the operation. The raid was launched to liberate captured Peshmerga who were believed to be in the jail, but who had since been moved, according to Kurdish officials.

Abu Wahid said that although most people in Hawija oppose ISIL, many of them are unable to afford the $400 fee that smugglers charge to sneak someone out of the city past ISIL guards.

He said that he does not regret working against ISIL. He explained that his subversive work was “my duty, and I did it for revenge against ISIL, who killed my brother”.

As the prisoners scrambled to freedom, one of their liberators checked Abu Wahid’s pockets and found his will.

Now he would no longer need it. One of the soldiers threw the wrapped letter on the floor as the men were rushed out to freedom, one by one.