US forces came under attack Wednesday in the West African nation of Niger — with three Green Berets killed and two others wounded, reports say.

Military officials told the New York Times that special operations troops were ambushed during a routine patrol near the Niger-Mali border. They had been training members of the Nigerien armed forces.

“We can confirm reports that a joint U.S. and Nigerien patrol came under hostile fire in southwest Niger,” said Lt. Cmdr. Anthony Falvo, a spokesman for the United States Africa Command in Stuttgart, Germany.

Three Army Green Berets were said to have been killed in the attack and two others wounded.

Officials told the Associated Press that the commandos were likely targeted by al Qaeda’s North African branch, al Qaeda in the Islamic Maghreb.

The deaths mark the first time that American soldiers have died while training armed forces in Niger.

The US military has been in the country providing training and security assistance to Nigerien soldiers following the rise of the ISIS-affiliated Boko Haram terror group and al Qaeda.

Terrorists have maintained a strong presence in the region since at least 2014.

“US Forces are in Niger to provide training and security assistance to the Nigerien Armed Forces, including support for intelligence, surveillance and reconnaissance efforts, in their efforts to target violent extremist organizations in the region,” Falvo told CNN on Wednesday night. “One aspect of that is training, advising and assisting the Nigeriens in order to increase their ability to bring stability and security to their people.”

The commandos who were wounded Wednesday were both taken to a hospital in Niamey, where they reportedly were listed in stable condition.

The extent of their injuries was unclear.