DIWANIYA, Iraq — Ali Hussein Kadhim, an Iraqi soldier and a Shiite, was captured with hundreds of other soldiers by Sunni militants in June and taken to the grounds of a palace complex in Tikrit where Saddam Hussein once lived.

The militants, with the Islamic State in Iraq and Syria, separated the men by sect. The Sunnis were allowed to repent for their service to the government. The Shiites were marked for death, and lined up in groups.

Mr. Kadhim was No. 4 in his line.

As the firing squad shot the first man, blood spurted onto Mr. Kadhim’s face. He remembered seeing a video camera in the hands of another militant.

“I saw my daughter in my mind, saying, ‘Father, father,' ” he said.

He felt a bullet pass by his head, and fell forward into the freshly dug trench.