KABUL, Afghanistan -- At least a dozen Islamic State militants accidentally blew themselves up in eastern Afghanistan Sunday during a botched operation to plant a bomb, a local official said.

"They were attempting to move an IED (improvised explosive device) to a crowded area of Achin, but it went off before they reached the planned place,” said Attaullah Khogyani, spokesman for Nangarhar province's provincial governor.

Twenty-one other militants were wounded, Khogyani said. There were no civilian casualties.

In recent months, Afghan security forces have been battling Islamic State loyalists in Nangarhar's Achin district on the border with Pakistan.

On Saturday, 24 militants were killed in ongoing operations, the Afghan army said in a statement.

The Islamic State group, which controls large areas of Syria and Iraq and has a growing presence in Libya, has struggled to establish a foothold in Afghanistan. The group's adherents in Afghanistan have faced strong resistance from security forces and the local Taliban. Most of the estimated 1,000 to 3,000 Afghans pledging loyalty to the group are believed to be former Taliban fighters.

President Ashraf Ghani said earlier this month that the Islamic State essentially had been defeated in the country's eastern border regions near Pakistan, where the group had overtaken some remote districts over the past year.

Earlier this year, after an attack on the Pakistani consulate in the eastern city of Jalalabad, President Barack Obama gave U.S. commanders the authority to strike Islamic State targets in Afghanistan -- the first such order allowing the U.S. military to attack the group outside its strongholds in Syria and Iraq.