Boko Haram fighters attacked the northeast Nigerian city of Damaturu for the first time since late 2014, residents said, after troops forced thousands to flee a village across the state border because of a planned military offensive.
Two locals in the Yobe state capital said suspected IS-linked Boko Haram fighters were behind the attack, which began late afternoon.
"Boko Haram jihadists launched an attack on Damaturu at about 5:45 pm (1645 GMT), firing guns and throwing explosives," Adamu Sani, a trader in the city's Maisandari area, told AFP.
"Residents and businesses all closed as we fled into the city to avoid being caught up in the attack. While fleeing into the city, I saw truckloads of soldiers heading to Maisandari."
Hashimu Idris, a civil servant, added: "Everybody is indoors. We pray the soldiers push them back otherwise it will be another disaster in the city.
"This is the first attack on the city since 2014."
Boko Haram fighters loyal to the faction headed by Abubakar Shekau launched a dawn raid on Damaturu on December 1, 2014. More than 150 people, including 38 police, were killed.
That raid followed a bomb attack on June 18 that year that killed some 21 football fans watching a World Cup match at a public viewing centre.
The previous October, 30 people, all of them thought to be soldiers, were killed in a gun and bomb attack on police buildings in Damaturu.
The latest attack followed the evacuation of some 2,000 people from Jakana village, some 90 kilometres (55 miles) from Damaturu on the road to Maiduguri, in neighbouring Borno state.
The National Emergency Management Agency (NEMA) said troops escorted the residents to the Bakassi camp for internally displaced people (IDPs) in Maiduguri "for their own safety".
NEMA northeast coordinator Abulkadir Ibrahim said the move was "a result of ongoing operations to flush out insurgents in the area".
Jakana residents said they were given no notice. One of them, Modu Kaka, said: "The soldiers came this morning and told us to assemble and began herding us into trucks.
"We left all our possessions in Jakana and we are now dependent on food aid."
Bakassi is one of several IDP camps housing tens of thousands of displaced people, who live in squalid shelters and rely on food handouts from aid agencies.
An unnamed military official said the evacuation was in preparation for a "big operation" against Islamic State West Africa Province (ISWAP), the IS-linked faction of Boko Haram.
Jakana lies on a known crossing route for ISWAP fighters moving between their camps in the Benisheikh forest area of Borno and their hideouts in the Buni Yadi area of Yobe.
In January ISWAP sent letters to Jakana and Mainok residents asking them to vacate their homes for an impending raid on the military.
The jihadists have in the last few weeks been under assault from intensive air and ground offensives from coalition forces involving Nigeria, Chad and Cameroon against militant camps in Lake Chad, according to military sources and militia groups.
"We know they are going to use their traditional route to escape," the military source said.
Boko Haram's decade-long insurgency has killed more than 27,000 people in the northeast with 1.8 million still displaced from their homes.
The conflict has spread to neighbouring Niger, Chad and Cameroon, prompting a regional military coalition against the jihadists.