The Taliban called it a "revenge attack" for US air strikes in the province of Kunduz earlier this month that left up to 32 civilians dead.
A powerful Taliban truck bomb struck the German consulate in Afghanistan's northern Mazar-i-Sharif city late Thursday, killing at least two people and wounding more than 100 in a major militant assault in the war-torn country.
The Taliban called it a "revenge attack" for US air strikes in the volatile province of Kunduz earlier this month that left up to 32 civilians dead.
The huge explosion, followed by sporadic gunfire, reverberated across the usually tranquil city, smashing windows of nearby shops and leaving terrified local residents fleeing for cover.
"The suicide attacker rammed his explosives-laden car into the wall of the German consulate," local police chief Sayed Kamal Sadat told AFP.
The German foreign ministry said the attack had ended and that all German staff from the consulate were unharmed.
"The consulate building has been heavily damaged. It is not yet clear how many Afghan civilians and security personnel died or were injured in the attack," the ministry said in a statement.
"Our sympathies go out to the Afghan injured and their families."
A diplomatic source in Berlin said Foreign Minister Frank-Walter Steinmeier had convened a crisis meeting.
"There was fighting outside and on the grounds of the consulate," a ministry spokesman said. "Afghan security forces and Resolute Support (NATO) forces from Camp Marmal (German base in Mazar-i-Sharif) are on the scene."
Afghan special forces cordoned off the consulate, previously well-known as Mazar Hotel. Helicopters were heard flying over the diplomatic mission early Friday as ambulances with wailing sirens rushed to the area, according to an AFP reporter near the scene.
At least two dead bodies and more than 100 wounded people -- including at least 10 children -- had so far been brought to two city hospitals, said local doctor Noor Mohammad Fayez. Some of the wounded were in a critical condition, he added.
The carnage underscores worsening insecurity in Afghanistan as Taliban insurgents ramp up nationwide attacks despite repeated government attempts to jump-start stalled peace negotiations.
Taliban spokesman Zabihullah Mujahid said the "martyrdom attack" on the consulate had left "tens of invaders" dead. The insurgents routinely exaggerate battlefield claims.
Posting a Google Earth image of the consulate on Twitter, Mujahid said the assault was in retaliation for American air strikes in Kunduz.
US forces conceded last week that its air strikes "very likely" resulted in civilian casualties in Kunduz, pledging a full investigation into the incident.
The strikes killed several children, after a Taliban assault left two American soldiers and three Afghan special forces soldiers dead near Kunduz city.
The strikes triggered impassioned protests in Kunduz city, with the victims' relatives parading mutilated bodies of dead children piled into open trucks through the streets.
Civilian casualties caused by NATO forces have been one of the most contentious issues in the 15-year campaign against the insurgents, prompting strong public and government criticism.
The country's worsening conflict has prompted US forces to step up air strikes to support their struggling Afghan counterparts, fuelling the perception that they are increasingly being drawn back into the conflict.
The latest attack in Mazar-i-Sharif comes just two days after a bitter US presidential election.
Afghanistan got scarcely a passing mention in the election campaign -- even though the situation there will be an urgent matter for the new president.
President-elect Donald Trump is set to inherit America's longest war with no end in sight.