"It was a misunderstanding between the American guards at the U.S. Embassy and our soldiers who were unloading weapons," said Kabul Police Chief Basir Salangi.
Salangi said three Afghan soldiers were killed and two wounded. Hospital officials said another soldier died shortly after being brought in.
Gen. Abdul Raouf Taj, chief commander for the Kabul district where the embassy is located, also said four Afghan soldiers had been killed. He said four others were wounded.
There were no apparent U.S. casualties.
Lt. Col. Paul Kolken, a spokeswoman for the international peacekeepers that patrol the capital, said there were unconfirmed reports that the Afghan soldiers shot first, firing at a passing car in front of the U.S. Embassy for unknown reasons.
"In doing so, they fired in the direction of the American embassy and the American soldiers standing guard there returned fire," Kolken said.
He said the first shots were fired just after 10 a.m., adding the incident was still being investigated.
Tension has been high in the Afghan capital in recent months. There was an explosion not far from the U.S. Embassy in April, and a rocket slammed into the nearby headquarters of international peacekeepers on March 30. Neither attack caused any casualties.
The shooting came a day after the United States raised its terror alert level, warning of possible attacks on Americans.
U.S. embassies around the world are on heightened watch following the decision by Washington to raise the terrorism alert to orange, signifying a "high" risk of attacks.
Also Wednesday, President Bush's special envoy to Afghanistan, Zalmay Khalilzad, was due to visit Afghanistan. It was not clear if he was in the capital at the time of the shooting.
Khalilzad's convoy was seen leaving the embassy about two hours after the shooting, heading in the direction of the presidential palace at the end of the street.
International peacekeepers in armored trucks mounted with machine guns tried to block off the area around the embassy following the shooting, with Afghan military vehicles blocking streets leading to the U.S. compound.
The heavily-policed road where the shooting occurred is also home to the international peacekeeper's base, an Afghan intelligence agency barracks and leads to the Presidential Palace.
Salangi said the soldiers were delivering the weapons to the intelligence agency across from the embassy.
"They wanted to unload the weapons to store them inside the brigade, which belongs to the intelligence service," he said.
U.S. embassy and Afghan government officials had no immediate comment.
There are 11,500 soldiers from 23 countries still in Afghanistan, and roughly 9,000 Americans. Early this month, Defense Secretary Donald Rumsfeld declared the end of major combat there.
On Tuesday, the war-torn country's fledgling government made a step toward greater stability when Afghan governors, responding to a resignation threat by President Hamid Karzai, agreed to transfer customs revenues to the central government.
Afghanistan's border provinces straddle lucrative import routes ruled by powerful warlords, who keep most of the revenues from customs duties for themselves, leaving the central government heavily dependent on foreign aid.
This year, donors are supplying $350 million of the government's budget, while Karzai's administration is expected to raise $200 million. Karzai said customs revenues alone should bring in $600 million.
U.S. troops have been involved in apparent "friendly fire" incidents in Afghanistan before. In April, an American warplane mistakenly bombed a house, killing 11 civilians near Afghanistan's eastern border with Pakistan.
Last summer, an American air attack was blamed for killing 48 civilians and wounding more than 100 who were attending a wedding.