DIFFA, Niger — The military convoy was rumbling across a river near the border last month when soldiers suddenly realized they were surrounded. More than 100 Boko Haram fighters, some of them on horseback, had encircled the vehicles, ready to strike.

The 300 soldiers from Niger and the handful of American Special Operations forces accompanying them called for help. Soldiers from Chad rushed to the area, and fighter planes from Niger buzzed overhead, bombing the militants, killing some and sending others fleeing. This time, at least, the quick international teamwork averted what could have been a deadly militant ambush.

Defeating Boko Haram was a flagship campaign promise of President Muhammadu Buhari of Nigeria, the former general who took office a year and a half ago. Since then, the Nigerian military, aided by neighboring countries — along with training from the United States, Britain and France — has made huge advances. Mr. Buhari has claimed for months that Boko Haram has been defeated, and this month he reveled in the release of 21 of the nearly 300 girls kidnapped from a school by Boko Haram more than two years ago.

Yet a troubling new series of attacks in Nigeria and the neighboring country of Niger, including one that killed dozens of soldiers, highlights how Boko Haram is far from eliminated. With the rainy season ending and roads becoming passable again, officials are bracing for more ambushes like the one at the river crossing.