Afghan and international troops returned fire and called in air support following the attack, the joint statement said.
"The insurgents withdrew and Isaf (International Security Assistance Force)-Afghan forces are in pursuit."
The US military said three of those killed in the attack were American soldiers.
The Latvian military later announced that two of its soldiers were also killed in the clash.
"The Latvian soldiers were on a mission to train the Afghan National Army," Normunds Stafeckis, a spokesman for Latvia's defence ministry, said.
He said the attack also wounded several other soldiers.