Dozens of Islamic State West Africa Province (ISWAP) fighters tried to break into the Wawa military cantonment in the remote New Bussa village near the border with Benin Republic late on Saturday to free more than 1,000 of their comrades detained there, the military officers told AFP.
"The terrorists attacked the base around midnight in large numbers but they were pulverised with air support, leading to the death of eight of them," one military officer said.
Three of the attackers, including their commander, were captured in the fight, the officer said.
Troops at the base had received intelligence militants were preparing an attack and waited for them, said a second officer who gave the same toll.
The jihadists tried to blast their way though the gates the base with dynamite and heavy guns, but met "stiff resistance" from troops at the base, said the second source.
"It was obvious they wanted to free other terrorists being held in the facility as they did in Kuje Prison," said the officer.
He was referring to the jail break at the Kuje prison near Nigeria's capital Abuja in June where ISWAP fighters blasted their way into the prison, freeing hundreds of inmates, including more than 100 high-profile jihadists.
The Wawa base houses around 1,700 jihadist suspects that have been in detention for the past five years.
The base was used between 2017 and 2018 as a court to try some of the 2,500 Boko Haram and ISWAP suspects.
Increasingly ISWAP has claimed attacks far from the northeast, including in Kogi and Niger states that both border the Federal Capital Territory, where Abuja is located.
The Wawa attack is the latest pointing to the group's growing influence in Niger state where officials and security analysts have been expressing concern over growing ties between the jihadists and criminal gangs called bandits.
Nigeria's police on Friday said they had beefed up security especially in the capital after the United States and Britain warned of a high "terror" threat in Abuja.
The US has given no details but has ordered diplomats' families to leave Abuja due to what it called a "heightened risk of terrorist attacks."