A homicide attacker blew himself up next to German soldiers shopping in a crowded market in northern Afghanistan on Saturday, killing eight people and wounding 16, officials said.

Three German soldiers were killed and two wounded in the attack, said Gen. Noor Mohammad Omarkhail, the deputy provincial police chief.

Five Afghan civilians were killed and 13 wounded, said Azizullah Safer, the director of the provincial health department. In addition, one translator working for the Germans was wounded.

A spokesman for NATO's International Security Assistance Force confirmed there was an attack but didn't immediately have details.

"We do know there was an attack in Kunduz, and we do know there was some ISAF casualties, which means dead or wounded," said Maj. John Thomas.

The provincial police chief, Gen. Ayub Salangi, said two German vehicles on a security patrol drove into the market area, where soldiers got out on foot to do some shopping.

"They were on a patrol, but they had gotten out of their vehicles with their translator to buy something in the market when the attack happened," he said.

German soldiers are responsible for northern Afghanistan, which sees relatively few attacks and is considered a much safer region than southern or eastern Afghanistan, where most of the country's fighting takes place.

Elsewhere, militants attacked U.S.-led coalition and Afghan forces less than 75 miles northeast of Kabul, sparking a rare gunbattle close to the capital that killed an estimated 20 militants, officials said Saturday.

Afghan and allied forces were on combat patrol late Friday in the al-Asay Valley in Kapisa province, which borders Kabul province, where the capital is, when they were ambushed, the U.S. coalition said.

The militants placed roadside bombs along the route in a "failed attempt to trap" coalition forces, a coalition statement said. Fighter aircraft fired on the militants, the statement said.

The coalition said "several dozen enemy fighters were estimated killed" during the fight and that there were no reports of civilian casualties.

Gov. Abdul Satar Murad, the governor of Kapisa province, said about 20 fighters were killed, and he said there were unconfirmed reports of civilian casualties.

While fighting in southern and eastern Afghanistan has picked up in recent weeks, battles so close to the capital are considerably rarer.

A joint U.S.-Afghan operation in Kapisa in November was credited with scattering several hundred fighters who had gathered in the region's steep valleys and mountainous terrain and who threatened the capital, Kabul, and the nearby U.S. base at Bagram. That operation also busted a suicide cell that had launched several attacks in Kabul last fall.

The coalition, meanwhile, said about 20 Taliban fighters ambushed coalition soldiers and Afghan police patrolling near the Pakistan border in the eastern province of Paktia on Friday, sparking an eight-hour battle that killed "a significant number of insurgents."

Troops called in airstrikes that destroyed "several enemy positions," the coalition said.

Ghulam Dastageer, the deputy provincial police chief, said the clash killed up to 60 fighters, though the only proof he offered was that officials found 60 abandoned weapons at the battle site.

He said it was possible there were Chechen, Arab and Pakistani fighters among the insurgents.