Thousands of civilians have fled the town, along with soldiers, they added.
However, military sources said the army was still in control of Bama, the second biggest town in Borno state.
Last month, Boko Haram said it had established an Islamic state in the towns and villages it controls in north-eastern Nigeria.
If confirmed, the capture of Bama would be an extremely significant development and would raise concerns that Boko Haram’s next target will be Maiduguri, the state capital about 44 miles away.
Boko Haram captured Bama, which the 2006 census showed had a population of about 270,000, after heavy fighting on August 31 and September 1.
The militants, who travelled in tanks and armored trucks, first seized the military barracks in the town, residents said.
Nigerian security sources said the assault had been repelled and about 70 militants had been killed, news agencies report.
The air force was used to “dislodge the swamp of terrorists” from Bama, the military said on its Twitter account.
An overnight curfew has been imposed in Maiduguri to prevent “infiltration” by militants after the “heavy casualties” they suffered, it added.
Boko Haram’s five-year insurgency has intensified in recent months despite the deployment of thousands of extra troops to the worst-affected areas.
In April 2014, Boko Haram captured more than 200 girls from a boarding school in the town of Chibok, also in Borno state.
kP_dLXUWLhwImage source: Wikimedia Commons President-elect Donald Trump celebrated his election victory at the Ultimate Fighting…
Millions of voters across the US chose to return Donald Trump to the White House…
Donald Trump declares victory in the US election as he addresses jubilant supporters in Florida.…
Stocks around the world are rising as Donald Trump appears to be on the cusp…
Donald Trump has won Pennsylvania, North Carolina and Georgia and taken a lead over Kamala…
Quincy Jones, the celebrated musician and producer who worked with Michael Jackson, Frank Sinatra, Ray…