Army spokesman Ezindu Idima said in a statement government troops "had a fierce encounter" before thwarting the militants who came in large numbers to loot food items and other valuables.
Five Nigerian soldiers were killed when Boko Haram overran a military base in the restive northeast two days ago, the army said on Sunday.
A column of militants from a Daesh-affiliated group stormed into the base in the town of Magumeri, 50 kilometres (30 miles) from the Borno state capital Maiduguri late Friday.
Army spokesman Ezindu Idima said in a statement government troops "had a fierce encounter" with the militants who came in numbers to loot food items and other valuables.
"The indefatigable troops effectively thwarted the terrorists' plan through superior fire power," he said.
"However, during the encounter the terrorists suffered heavy losses/casualty. Unfortunately, five soldiers paid the supreme price," he said.
The militants were said to have arrived in the town around 5:00 pm (1600 GMT) and engaged troops in an hour-long fight.
But militia leader Gremah Kaka said the militants "gained the upper hand and chased the troops away."
"The insurgents overpowered the soldiers and forced them to flee into the bush," he said.
Kaka said the militants stayed in the base for "more than four hours" before they were dislodged by reinforcements from another base in Gubio, 46 kilometres away.
Last week, the militants raided a military base in Mararrabar Kimba, 135 kilometres from Maiduguri, killing five troops and stealing weapons, while some 30 troops are listed as missing.
ISWAP has since July last year targeted dozens of military bases in attacks that saw the militants kill scores of soldiers.
Boko Haram's decade-long campaign of violence has killed 27,000 people and displaced around two million in Nigeria.
The violence has also spilled over into neighbouring Niger, Chad and Cameroon, prompting a regional military coalition to defeat the militant group.