MAO, Chad — An oath of allegiance from Boko Haram, the Nigeria-based militant group, to the Islamic State on Saturday reinforces Western fears that the terrorist group is growing beyond its base in Iraq and Syria. These worries have prompted American and allied commandos to rush to train African counterterrorism troops to fight extremists on the continent.

The expanding effort here on the edge of the Sahara to fight militancies like Boko Haram comes as the group has kidnapped schoolgirls, slaughtered thousands of people, and now has expanded its attacks from Nigeria into Cameroon, Niger and Chad.

“When your neighbor’s house is burning, you have to put it out, because if not, yours is next,” said Lt. Col. Brahim Mahanat, a Chadian Army officer who spoke during the Pentagon’s annual military exercise with 1,200 African troops, United States Army Special Forces and other Western commandos, which ends on Monday.

More than any exercise in the past decade, this year’s training — three weeks of marksmanship, mock ambushes and patrols in harsh desert terrain — is bumping up against real-world operations. The Chadian capital, Ndjamena, is just 30 miles from militant-held territory in Nigeria, and Boko Haram has vowed revenge since Chad began cross-border attacks against the militants. Police officers and army troops have stepped up patrols in the capital in response to increased risks, including suicide bombings.