The military says the battle erupted after gunmen fired on U.S. troops and Afghan police investigating a reported beating of a villager .