Twenty-three soldiers were killed in a “terrorist” ambush in western Niger during an offensive near the border with Burkina Faso and Mali, the defence ministry said.