TARMIYA, Iraq — Islamic State militants dressed in Iraqi military uniforms launched a brazen nighttime attack in a farming hamlet close to Baghdad, killing 21 members of a local tribe that has been a vocal opponent of the extremists, security officials and residents said Wednesday.
The hourlong gun battle late Tuesday in this rural area approximately 25 miles north of the capital threatens growing optimism among both Iraqi officials and the international coalition fighting the Islamic State that Iraqis are gaining momentum in their efforts to stabilize cities and communities devastated by violence.
Although Iraqi forces are still engaged in mopping-up operations to rid pockets of the country of sleeper cells, terrorist attacks and civilian deaths have dropped sharply since the government declared victory over the Islamic State in December. In April, only 68 Iraqi civilians were killed in acts of terrorism, violence and armed conflict, according to the United Nations, continuing a steep decline of violence in a country once plagued by almost daily suicide bombings and other terrorist attacks.
But the high death toll on Tuesday — 18 men, two women and a 5-year-old girl — and the timing of the attack are especially worrisome. Iraqi security forces were already on high alert across the nation ahead of national elections scheduled for May 12.
The authorities said they had no leads about how the attack was executed or who was responsible. The Islamic State media outlet Amaq released a statement on Wednesday claiming responsibility for the attack.
All the victims were members of the Albu Faraj tribe, known for its staunch opposition to Sunni extremists in the area, a notorious safe haven for suicide bombers and terrorists seeking to infiltrate the capital. Several prominent members of the tribe work for a local Sunni militia that is part of Iraq’s popular mobilization forces, created in 2014 to help defend Iraq against the Islamic State.
Witnesses said the militants, all of whom were masked and wearing army uniforms, sneaked into the village after Tuesday evening prayers, apparently by fording a nearby river. They walked down a dirt road to the home of a local lawyer, Rahim Marzouk, who was known for his work on behalf of victims of the Islamic State.
When Mr. Marzouk answered the door, the gunmen opened fire, killing him, his wife, his teenage son and his 5-year-old daughter, said a neighbor, Khaled al-Salah, who rushed to the street when he heard the gunfire just a few feet from his home.
Mr. Salah and his son ran toward the victims, intending to try to get them medical attention. But gunmen, some perched on nearby rooftops, opened fire on them and other neighbors who were running to the scene.
“The attackers knew us — they knew we were all related here and would try to help each other,” said Mr. Salah, who was hit in the shoulder. “It was like an ambush.”
Mr. Salah’s brother and nephew were among those killed. Thirteen other people were wounded, according to the head of the hospital in nearby Djail, where the bodies were taken.
Gen. Qassim Attiyah, the spokesman for the Baghdad Operations Command, which is responsible for security around Tarmiya, said the attackers had melted away before a nearby army unit could reach the scene on Tuesday night. An overnight search in surrounding fields and farmland yielded no immediate clues about where the militants escaped to, he said.
“We are pleading with the local residents to help us,” General Attiyah said. “Someone has to know where they went.”
The area around Tarmiya has long been known as a haven for jihadists, part of the so-called Baghdad belt, a notorious farmland area where Sunni extremist militants built factories for bombs that once targeted American forces in Iraq.
Since 2014, Iraqi intelligence and security forces have identified the area as a staging ground for Islamic State attempts to send suicide bombers in Baghdad. The road through Tarmiya connects the capital to three former Islamic State-held territories.
Three weeks ago a school principal in Tarmiya was arrested on suspicion of providing a safe house for a suicide bomber who set off her explosives inside the empty school building when security officials learned of her presence and started moving in on her, General Attiyah said.
On Wednesday afternoon, Tarmiya residents gathered for a funeral service for their 21 neighbors, many still shaken by the violence that tore apart their community.
Amer Al Khazraji, head of the provincial council, blamed the Baghdad Operations Command for the security breach. He requested an urgent investigation into how the attack could have happened.
Hadi Attiyah, another neighbor who witnessed the attack, said it was like seeing his worst nightmare come true.
“I had told our tribal militias that they needed to be more vigilant. I told them not to be lazy, that Daesh would be coming for us,” Mr. Attiyah said, using an Arabic acronym for the Islamic State. “They didn’t listen.”