A heavily armed Taliban commander was killed Saturday during an pre-dawn shootout at a mosque in eastern Afghanistan, NATO said as it reported an American service member was killed in a separate attack.

A joint Afghan-international force went to a compound in Wardak province to look for an insurgent believed responsible for planning attacks and buying weapons and parts for making bombs, the international coalition said. When the joint force approached the compound, the Taliban commander, who was armed with grenades and hundreds of rounds of ammunition, ran to a nearby mosque.

Afghan security forces surrounded the mosque outside the town of Pirdad in the Nirkh district and called for him to surrender. When he didn't, they went inside.

"The Taliban commander opened fire with his AK-47 while in the mosque and was killed by the Afghan security force," NATO said in a statement.

NATO said Taliban insurgents frequently seek protection in mosques, but the Afghan-international force says it does everything possible to avoid fighting in or around any known mosque.

Abdul Haq, acting police commander of Nirkh province, said the shooting actually occurred in the mosque compound, not inside the mosque itself. The shootout was at about 3 a.m.

"As the Afghan forces were about to enter the mosque, he escaped through a window," Haq said. "For the second time, the Afghan forces shouted at him to stop. He didn't, and they opened fire on him and he was killed. He was not killed inside the mosque, but in the mosque compound."

Separately, NATO said an American service member died following a roadside bomb attack Friday in southern Afghanistan. No other details were disclosed.

Also in eastern Afghanistan, the military said a joint force Friday night in Khost province captured several militants, including a known operative of the Jalaluddin Haqqani militant network, which is linked to Al Qaeda. The joint force retrieved several AK-47 rifles, hand grenades and bomb components from the operative's home in the Sabari district.