The military had repeatedly denied that the group had captured the town and dislodged soldiers.
The Nigerian military successfully expelled Boko Haram militants from the town of Baga in the Kukawa area of Borno State following a fierce firefight during which two Nigerian soldiers were killed, the military said.
Baga is a major commercial town in northern Borno which Boko Haram captured recently.
Brigadier-General Sani Usman, a spokesperson for the army, confirmed the deaths of the soldiers while praising their bravery.
However, earlier the military had repeatedly denied Boko Haram had captured Baga and dislodged soldiers, including those from the Multi-National Task Force.
Usman said several Boko Haram terrorists were “dealt with” while troops continued to go after the remaining fleeing insurgents. He did not, however, give details of casualties recorded on the side of the outlawed Boko Haram group.
Nigeria has been battling the insurgents since they launched an insurgency in 2009.
Thousands have been killed in the ongoing conflict and many more displaced and injured, with Borno State in the north-east being the epicentre of militants’ attacks on civilians and military personnel.
The insurgency has also spread to neighbouring countries Cameroon, Chad, and Niger.