A man in an Afghan army uniform has killed two German soldiers serving with Nato's Isaf force in the northern province of Baghlan, Nato says.
Isaf soldiers returned fire "critically injuring the shooter", Nato said.
At least eight other Germans were injured in the attack in the provincial capital, Pul-e Khumri.
Germany has some 5,000 troops stationed in Baghlan and other provinces in northern Afghanistan. Security has been worsening in the area in recent months.
"We are not sure if this was actually an Afghan National Army soldier, or just a criminal, a terrorist, wearing a uniform," said German Brig Gen Josef Blotz, a Nato spokesman in Kabul.
He said troops had been mending a vehicle on a roadside outside a coalition compound in Pul-e Khumri when the attacker opened fire.
Two senior security officials in Pul-e Khumri had earlier told the BBC's Bilal Sarwary that the Afghan soldier opened fire "all of a sudden".
The man is believed to have been serving with the second brigade of 209 Shaheen corps. German and Afghan soldiers are jointly stationed at a base outside the city, our correspondent reports from Pul-e Khumri.
Baghlan used to be among a number of relatively peaceful northern provinces which have become steadily more violent in recent months as the insurgency has spread.
The Afghan National Army (ANA) has strict security screening procedures for its recruits, but that has not prevented a number of shooting incidents in which foreign soldiers have been killed.