KABUL - Taliban fighters attacked a detachment of German troops Friday who were on a bridge-building and mine-clearing mission, triggering a gunbattle that left three soldiers dead, the German Defense Ministry said.

Five other Germans were wounded in the fighting southwest of Kunduz city, the ministry said.

German troops and Afghan police exchanged fire with their attackers for about an hour, with fighting resuming three hours later, local government chief Abdul Wahid Omar Khil said. He estimated there were about 200 Taliban militants involved in the engagement.

One Taliban fighter was killed and another was wounded, but the Germans and Afghan police were unable to use heavy firepower because the militants were firing from inside and on top of civilian homes, Omar Khil said.

Kunduz provincial police Chief Gen. Abdul Razaq Yaqoubi said the battle began after a mine exploded under a German armored vehicle. He said the troops were preparing to build a bridge and clear mines in the Chahar Dara area, about 12 kilometres from the provincial capital.

Berlin has more than 4,000 troops in Afghanistan -- the third largest foreign troop contingent in the country -- as part of the NATO presence fighting the Taliban and seeking to establish central government authority.

German forces control much of the country's north, which is relatively peaceful. The surroundings of Kunduz, however, have recently proven increasingly volatile.

Including Friday's casualties, 22 German soldiers have been killed by fighting or attacks in Afghanistan since 2001 and another 138 wounded, according to the Defense Ministry.

Another 17 German soldiers died of natural causes or accidents while on duty in Afghanistan.

Also Friday, a main political rival accused Afghan President Hamid Karzai of undermining the war against the Taliban by blaming the international community for the controversy over last year's disputed election.

Abdullah Abdullah -- who dropped out of a presidential runoff against Karzai saying it would be a repeat of the fraud-marred election -- also said he was worried about the president's recent behavior, describing it as erratic.

"As a former colleague and doctor, I think this is beyond a normal attitude," said Abdullah, who served as foreign minister during Karzai's first term.

Abdullah spoke to reporters a day after Karzai accused the UN and international community of trying to rig the presidential election in order to either deny him a second term or tarnish his victory.

Afghanistan's election commission declared Karzai the winner of the Aug. 20 balloting, but a UN-supported independent complaints commission threw out nearly a third of his votes, forcing him into a runoff with Abdullah. It took a flurry of high-level diplomatic visits and intense international pressure for Karzai to accept that he had not won the election in the first round.

White House press secretary Robert Gibbs says Karzai's harsh words about foreign countries are "genuinely troubling," and the administration is seeking clarification of what he meant.

The Obama administration and its NATO allies are depending on Karzai's government to be a reliable partner in the war against the Taliban. Gen. Stanley McChrystal, the top U.S. and NATO commander in Afghanistan, believes the support of the Afghan people for the government is key to winning the war.

During the news conference, Abdullah accused Karzai of undermining the morale of Afghan forces battling the stubborn Taliban insurgency by implying that Afghanistan was still a country under foreign occupation.

"It was extraordinary ... this is treason to the national interest," he said. "What is the message to the thousands of soldiers and national police defending the country?"

"(Karzai) thinks that by taking that message he has delivered a populist stance, an anti-foreigner message," Abdullah said. "He tried to blur the line between national resistance to terrorism and the insurgency."

Karzai's comments, delivered Thursday to employees of the state election commission, came after parliament rejected his bid to expand his control over the country's electoral institutions. The remarks were seen as sharpening the power struggle with an increasingly independent-minded parliament over whether foreigners will help oversee parliamentary elections scheduled for September.

During his speech Thursday, Karzai acknowledged there had been "vast fraud" in the August vote, which returned him to office for a second five-year term. But he blamed the fraud on the UN and other foreign organizations.

Turning the accusation back on Karzai, Abdullah said it was clear the president and his supporters were the ones responsible. Two good things came out of Karzai's comments, he said.

"First, the admission that there was massive fraud; and second, the admission that his rule was in fact illegitimate," Abdullah said.