NIAMEY, Niger — Gunmen on motorcycles and pickup trucks killed 13 soldiers and wounded five others in an attack on their base in western Niger, security authorities said on Saturday.

The village is near the border with Mali, and a few dozen miles from where militants killed four American soldiers in an ambush on Oct. 4 that has thrown a spotlight on a United States counterterrorism mission in Niger, a country that straddles an expanse of the Sahara.

Niger’s military officials confirmed the attack. The assailants had come across the border from Mali and drove about another 25 miles to the village of Ayorou before springing their attack, the security authorities said.

"They were heavily armed,” said a security official on the scene. “They had rocket launchers and machine guns. They came in four vehicles each with about seven fighters.”