clip_53Muhammad Hassan Abdullah al-Jibouri had little hope that he would ever make it out of the Islamic State’s jail alive, and he had not even seen the sun in more than a month. Then, early one morning in late 2016, he heard the helicopters overhead.

The 35-year-old police officer heard bursts of gunfire, and shouts in Kurdish and in English. Suddenly, the door to his cell was battered open.

“Who is there? Who is there?” a soldier yelled, first in Kurdish and then in Arabic.

“We are prisoners!” Mr. Jibouri’s cellmates yelled back.

Mr. Jibouri was one of 69 Arab prisoners of the Islamic State freed in a military raid near the northern Iraqi town of Hawija last week, the first in which American Special Operations forces were confirmed to have accompanied their Kurdish counterparts onto the battlefield.

In their first interviews since being brought to the Kurdish autonomous region by American Chinook helicopters, four of the former prisoners described life under the thumb of the Islamic State.

As members of the police, or suspected of ties to the Iraqi government or the United States, the men were beaten and tortured by militants during their captivity. It was all suddenly reversed by a military mission that happened upon them by mistake — the raid had originally been meant to free captured pesh merga fighters.

Told by his Islamic State guards he was just hours away from execution, Saad Khalif Ali Faraj, a 32-year-old police officer, said he had spent his last night in captivity writing a letter to a nephew, urging him not to risk his safety by going searching for him.

“I told him: ‘Look after your brothers and your family,’ ” he recalled. “ ‘Don’t go out looking for me. They will kill me. Do not look for me.’ ”

In a two-and-a-half-hour interview at a government building in the town of Salahaddin in Iraqi Kurdistan, the former prisoners, all Sunni Muslims, gave accounts that illuminated life and punishment in one of the Iraqi areas long ago captured by the Islamic State, also known as ISIS or ISIL.

In Hawija, the militants’ draconian rules and regimented torture were not driven by sectarian hatred or foreign prejudices: This was a world in which Iraqi Sunnis brutally imposed their will on fellow Iraqi Sunnis. One of the militants’ main ringleaders in the area was from nearby Diyala Province, and some of the Islamic State fighters were from the Hawija area itself, according to the freed prisoners.

After the militants arrived, they went house to house, seizing weapons and money, recalled Muhammad Abd Ahmed, 35, who said he was on a leave from the Iraqi Army when the Islamic State swooped in. Disarmed and impoverished, Sunni men in the town were later offered $50 if they joined the militants.

The men described an array of exacting restrictions imposed by the militants. Local residents were told down to tiny details what to wear — the cuffs of men’s trousers had to be rolled up over the ankle, for instance — and precisely how to position their hands and fingers when praying. Disobedience or carelessness in following the rules provoked suspicion, or even beatings.

Trying to leave the Islamic State’s “area of control” was another offense that could lead to severe punishment, said Ahmed Mahmud Mustafa Mohammad, 31.

The militants were wary of anybody who had served in the Iraqi police or army, or whom they thought might have had contact with Americans or Kurds.

The fighters also had a growing need for a detainment network to house those who had come under suspicion. The freed men recalled that the militants referred to the Hawija compound they were kept in simply as “Prison No. 8.”

They said that new prisoners were subject to a methodical program of abuse — electrically shocked, beaten with hoses, smothered with plastic bags until they lost consciousness — even without any interrogation questions. Food was meager: pieces of bread pushed through cell doors.

Prisoners were kept in their cells day and night, and the rooms were jammed: Jibouri’s cell held 39 detainees, he said. And the Islamic State’s messaging was relentless. There was a television set in the cell that was used to play Islamic State videos of beheadings, and the captives were forced to watch.

Jibouri’s troubles began when his younger brother, who had taught English in Hawija, came under suspicion, was imprisoned and told he would be killed. He escaped, but the Islamic State exacted retribution by detaining Mr. Jibouri, three of his other brothers, his cousins and his 80-year-old father.

After a week, all but one of them was set free. The exception was an older brother who was killed as a warning to the family.