The firefight lasted roughly 30 minutes and involved less than a dozen United States troops and more than 20 Nigerien soldiers. The official said they ran into a large group of militants traveling in pickup trucks mounted with machine guns, known as technicals, that took them by surprise. United States drones were in the area, but it is unclear how close they were at the time of the attack given the mission’s perceived low risk.

French attack helicopters responded to calls for help but it is unknown if they fired on the militants or only made a show of force. The wounded were evacuated to the capital of Niamey and the wounded Americans were then put on a plane to Germany where they were receiving medical treatment.

The military has not yet released the names of the American soldiers killed, pending notification of their families. Dana W. White, the chief Pentagon spokeswoman, would not give new details about the episode in response to questions on Thursday, citing “ongoing operations.”

While no group has claimed responsibility for the attack, officials believe that Al Qaeda in the Islamic Maghreb was involved. The extremist group, pushed from its territory in northern Mali after the French military intervened in 2012, has been increasingly active in recent years. Since 2016 the group has staged a number of attacks across the broader Sahel, a stretch of territory that runs from Senegal to Sudan, and routinely ambushes United Nations peacekeepers in the region.

While the United States provides limited support to the French troops in Mali, namely sharing drone feeds and other intelligence, it has invested a significant amount of resources to the south in Niger, where about 800 American troops are stationed.

Since 2013, unmanned American aircraft have launched from a clandestine airfield in Niamey. Americans are also helping construct a $50 million drone base for French and American aircraft in Agadez. When completed next year, it will allow Reaper surveillance drones to fly from hundreds of miles closer to southern Libya, to monitor Islamic State insurgents flowing south and other extremists flowing north from the Sahel region.

More than two dozen Army Special Forces — like those attacked on Wednesday — train the Nigerien military and help with intelligence gathering for the local forces.