General Mohammed Daud, the military commander Kunduz, said one Afghan also died in the raid and four Chinese nationals were injured.
A spokesman for NATO-led peacekeepers in the town said a total of 16 people were hurt.
Up to 20 armed men stormed the workers' compound south of Kunduz in the middle of the night and opened fire with automatic weapons, the Chinese embassy said, describing the raid as a "terrorist attack".
"The enemies of Afghanistan, Taliban and Al-Qaeda" were responsible, said General Daud. He said the compound, which housed 90 workers, was attacked because it did not have security guards. However the Chinese news agency Xinhua said security guards at the site fought back.
The killings came against a background of spiralling violence in Afghanistan -- dozens of suspected Taliban militants have been killed by US-led forces in the past week and aid workers have been ambushed and attacked as the country prepares for elections in September.
The Interior Ministry said the attackers were armed with PK machine guns and AK-47s, and traveled in two small vehicles, a Corolla and a station wagon.
The compound was in Jalawgeer, a district some 36 kilometres (22 miles) south of Kunduz, spokesman Lutfullah Marshal told AFP.
The Chinese embassy said the victims were among 100 people working on the construction of a road for the China Railway Construction Shisiju Group Corporation. Many of the workers arrived in Afghanistan in the past week.
China's ambassador to Afghanistan Sun Yuxi was heading to the scene, some 250 km north of the capital, an official at the embassy, who did not want to give his name, told AFP.
Northern Afghanistan is considered
Kunduz is seen as a particularly safe area of Afghanistan as some 200 German peacekeepers are based in the town. The International Security Assistance Force soldiers provided blood for transfusions for the injured, who were taken to a hospital in the city, a spokesman for the peacekeepers told AFP.
The attack follows a spate of attacks targetting aid workers and foreigners by what the government believes are Taliban militants trying disrupt planning for the national elections.
Just over a week ago, three Europeans and two Afghans working for Medecins Sans Frontieres were shot dead as they travelled in northwestern Baghdis province by suspected Taliban, prompting fears that militants had moved out of their traditional areas ahead of the elections.
The country has also witnessed a new upsurge in fighting between US-led forces and supporters of the Taliban, which was ousted by US-backed Afghan forces in the aftermath of the September 11 terrorist attacks.
In the past week some 70 suspected Taliban have been killed in fighting on the ground and in US bombing raids in the southern Taliban heartland, according to Afghan officials.
Beijing formally reopened its embassy in Kabul in 2002 after evacuating the diplomatic compound in 1993 during heavy fighting in the Afghan civil war.
This is by far the most serious incident involving nationals from China, which shares a 40-kilometre border with Afghanistan, since the fall of the Taliban in late 2001.
In early May, three Chinese engineers from the China Engineering Harbour Co. were killed and nine others wounded in a seaport of neighbouring Pakistan when an explosive-laden car blew up as a van carrying 12 Chinese engineers and technicians was passing by. AFP