Before Kurdish and U.S. commandos arrived at his cell door last month, Hassan Abu Ahmed had not seen daylight for five months.

Held in an Isis prison near the northern Iraqi town of Hawijah, the 46-year-old was accused of being a spy and regularly tortured.

Sometimes a plastic bag was placed over his face until he nearly suffocated. He was electrocuted, beaten with plastic pipes and whipped with electric cable. There were mock executions.

“They’d put a gun to your head and say we are going to kill you now, and then shoot next to you,” Abu Ahmed said. “We always feared execution.”

Two prisoners held in the facility described life in an Isis prison and the mission that set them free. The operation, which a Kurdish commando also detailed, freed 69 detainees and was the first confirmed time that U.S. troops had directly accompanied Iraqi forces on the battlefield in the fight against Isis.

But the raid also claimed the life of a U.S. soldier, the first killed in combat since troops returned last year, highlighting the cost the United States faces amid a Pentagon push to expand military involvement in Iraq and Syria. Defense Secretary Ashton B. Carter recently summed up the new U.S. strategy against Isis as the “three R’s”: Raqqa, Ramadi and raids. Raqqa is the group’s stronghold in Syria, and the Iraqi city of Ramadi was captured by the militants earlier this year.

In pictures: Fighting between Kurds and Isis intensifies in Kobani Show all 30 1 /30 In pictures: Fighting between Kurds and Isis intensifies in Kobani In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani An explosion rocks Syrian city of Kobani during a reported suicide car bomb attack by the militants of Isis group on a People's Protection Unit (YPG) position in the city center of Kobani, as seen from the outskirts of Suruc, on the Turkey-Syria border In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani An explosion rocks the Syrian city of Kobani during a reported suicide car bomb attack by Isis Getty In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani An explosion in the Syrian city of Kobani set off as fighting continues Getty Images In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Heavy smoke rises following an air strike by the US-led coalition aircraft in Kobani Getty Images In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani An unidentified armed man takes position near a building in the Syrian town of Kobani, as seen from near the Mursitpinar border crossing on the Turkish-Syrian border in the southeastern town of Suruc in Sanliurfa province In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Kurdish fighters walk to their positions in Kobani In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Residents of Kobani walk in the streets of the besieged town, as seen from near the Mursitpinar border crossing on the Turkish-Syrian border in the southeastern town of Suruc in Sanliurfa province In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani People's Protection Unit (YPG) fighters walk in the Syrian town of Kobani, as seen from near the Mursitpinar border crossing on the Turkish-Syrian border in the southeastern town of Suruc in Sanliurfa province In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani People watch the Syrian town of Kobani from near the Mursitpinar border crossing, on the Turkish-Syrian border in the southeastern town of Suruc in Sanliurfa province In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani A Turkish soldier stands on a top of a tank as he watches the Syrian town of Kobani from near the Mursitpinar border crossing, on the Turkish-Syrian border in the southeastern town of Suruc in Sanliurfa province In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Smoke rises from the Syrian town of Kobani, seen from near the Mursitpinar border crossing on the Turkish-Syrian border in the southeastern town of Suruc. Kurdish forces defending Kobani urged a U.S.-led coalition to escalate air strikes on Isis fighters who tightened their grip on the Syrian town at the border with Turkey. A group that monitors the Syrian civil war said the Kurdish forces faced inevitable defeat in Kobani if Turkey did not open its border to let through arms, something Ankara has appeared reluctant to do In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Newly arrived People's Protection Unit (YPG) fighters walk in a line in the Syrian town of Kobani, seen from near the Mursitpinar border crossing on the Turkish-Syrian border In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Heavy smoke rises from the Syrian town of Kobani, seen from near the Mursitpinar border crossing on the Turkish-Syrian border in the southeastern town of Suruc in Sanliurfa province In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Kurdish women mourn at the grave of a relative, who was a Kurdish fighter killed in fighting with the militants of the Islamic State group in Kobani, and was buried at a cemetery in Suruc In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Turkish army tanks mechanized units take position on top of a hill near Mursitpinar border crossing in the southeastern Turkish town of Suruc in Sanliurfa province In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Smoke rises after an US-led air strike in the Syrian town of Kobani. The air strikes pushed Isis fighters back to the edges of the Syrian Kurdish border town of Kobani, which they had appeared set to seize after a three-week assault, local officials said In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani A huge plume of smoke rises after an airstrike in eastern Kobani, Syria, behind a hilltop where militants with the Islamic State group had raised their flag on Monday AP In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Turkish Kurds watch as airstrikes hit Kobani AP In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Smoke rises from the Syrian town of Kobani as Turkish army tanks take position on the Turkish side of the border Reuters In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Military aircraft flies over the Turkey-Syria border as it nears targets in Kobani In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Smoke rises after a US-led air strike in the Syrian town of Kobani Reuters In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Turkish Kurds, on the Turkey-Syria border, watch over the border at the intensified fighting between Isis and Kurdish forces AP In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Smoke rises during airstrikes on the Syrian town of Ain al-Arab, known as Kobani by the Kurds Getty In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani A huge plume of smoke rises after an airstrike outside west Kobani, Syria AP In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani A militant with the Isis group walks in the town of Kobani In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Militants with the Isis group, bottom, along with a machine gun-fitted pick up truck, partially seen bottom right, hold positions in Kobani, during intensified fighting with Syrian Kurds In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani People watch smoke rising from the Syrian town of Ain al-Arab, known as Kobani by the Kurds, after an air strike Getty In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Smoke rises from a strike at an area of a mosque that destroyed its minaret, in Kobani during heavy fighting between militants with the Isis group and Syrian Kurds In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani Militants with Isis hold positions in Kobani, Syria, during intensified fighting with Syrian Kurds AP In pictures: Fighting between Kurds and Isis intensifies in Kobani Kobani A partial view of Kobani with a mosque's minaret

The raid in Hawijah was supposed to be led by Kurdish forces, but U.S. troops were called in when they were pinned down.

Kurdish authorities had received intelligence that captured Kurdish soldiers, known as peshmerga, were being held at the makeshift prison. A mass grave measuring about 20 yards long had been dug on the prison’s grounds, and it was feared the detainees would soon be killed.

The operation was planned over five days, said a Kurdish commando who participated in the raid and spoke on the condition of anonymity, citing security protocol. The United States was asked to play a “logistics and support” role.

On 21 October, the day before the raid, Abu Ahmed said he heard drones buzzing overhead from the cell he shared with dozens of other prisoners who had fallen foul of the Isis’ draconian laws.

Abu Ahmed had been accused of supplying information to Kurdish authorities, something he admits he had done.

“I was giving information to people here because we wanted our areas to be liberated,” he said. “Eyewitness observation of what was happening in the area, numbers of Daesh people, whether they had any intention to attack,” he said, using an Arabic term for the Isis.

The Isis flag flying in Raqqa (MOHAMMED ABDUL AZIZ/AFP/Getty Images)

Abu Ahmed’s frequent trips to the nearby city of Kirkuk, outside Isis territory, had raised suspicions. When the militants seized control of Hawijah, about 150 miles north of Baghdad, in June 2014, he had resisted pressure to join them.

“They knew me personally very well, my family, my tribe,” he said. “They were looking for influential people to join.”

Life in the town went from “white to black” when the militants took over, he said.

In May, five armed Isis members appeared at his house to arrest him. After he was blindfolded and driven to prison that day, he did not see daylight for another five months.

He said he prayed for rescue but had little hope it would come.

But at 2 a.m. on 22 October, special forces from the Kurdish region’s Counter Terrorism Department launched their mission — accompanied by about 30 U.S. troops. U.S. Chinook and Black Hawk helicopters also took part.

Abu Ahmed heard the helicopters draw closer. When the guards started shouting, he realized that a rescue attempt was underway.

Iraqi security forces, backed by Sunni and Shia volunteers, clash with Isis militants on the front line in the eastern suburbs of Ramadi, in Iraq’s Anbar province (AP)

“Paratroopers, paratroopers!” the guards yelled in the confusion, he said. U.S. and Kurdish officials say no paratroopers were involved, with helicopters landing about 30 yards from the prison.

In another cell, Qassim Awad, 36, was jolted awake by the shouting guards.

“We heard the helicopters,” he said. “We were all scared and went to the bathroom and hid.”

Awad said he was in prison for attempting to escape Hawijah with his two wives and 10 children. He had been in prison for about two weeks before the rescue attempt.

The prisoners’ accounts of why they were held could not be independently verified. A Kurdish security officer was present during their interviews, which took place in a security building in Irbil. Two weeks after the raid, the former detainees are still being processed by Kurdish and U.S. authorities, with concerns that some may be Isis sympathizers who were arrested for minor offenses.

Awad said the prison’s main interrogator, a militant from neighboring Diyala province, was called “Abu Hajjar.” Awad, a truck driver who had served in the Iraqi military, said he lost some of his hearing after being beaten on the head with a plastic pipe.

“I confessed,” he said. “I couldn’t handle the torture. Other prisoners told me about the electric shocks, and I couldn’t handle it. I decided death was the best way out, but then they came.”

Isis hostages freed.mp4

Awad had put his fingerprint to a written confession, though he doesn’t know what it said because he was blindfolded at the time, he said.

He said he had been told that he was awaiting judgment from an Islamic State court, but he was expecting to be executed.

On the night of the raid, the Kurdish commando said his team came under fire from the prison guards as soon as the helicopters landed. The plan was for Kurdish forces to take the lead.

“They attacked us straight away,” he said. “At that stage we were leading the offensive.” The Kurdish forces fought back, killing two guards, he said. His team attempted to enter one of several buildings in the prison, formerly a house.

But then they came under fire again. “We were involved in an intense firefight so we requested support [from the Americans],” the commando said. “During that intense firefight, it was unfortunate that the American officer was martyred.”

When the U.S. forces and Kurdish forces reached Awad’s cell, he said, one prisoner who spoke some English cried out, “Please help us! Please help us!” The prisoners were searched and handcuffed before being sat on the grounds to wait to be airlifted out.

Kurdish forces searched for their peshmerga colleagues, but none were found.

Six Iis militants were arrested, according to Kurdish authorities, and 20 were killed. In a video released in the aftermath, Isis said just six militants had held off the attack, which it described as a “failed operation.” Twenty-five prisoners were killed, it claimed. The video showed four peshmerga being executed on the bombed remains of the compound in retaliation for the raid.

“Obama, you have learned a new lesson,” a masked Isis militant said in the video. “You did not gain anything, you returned to your bases, and with losses and humiliation.”

The American killed was Master Sgt. Joshua L. Wheeler, who had served 14 tours in Iraq and Afghanistan. He was 39.

His actions and those of one of his colleagues protected those who were involved in breaching the compound and made the mission successful, Carter later said.

“He was a capable officer. He will leave behind a gap,” said the Kurdish commando.