Hundreds of Boko Haram extremists tried to attack the biggest army base in northeast Nigeria overnight but met fierce resistance from soldiers who fired artillery throughout the night.

Booming cannon and whooshing rockets woke up people living around Giwa Barracks in Maiduguri, the northeast's biggest city. The ground shook as people prostrated themselves for evening prayers. Hundreds fled, though some were returning home on Thursday morning.

Many villagers were killed by shells that hit the outlying village of Kayamla, where the soldiers engaged hundreds of militants, according to Muhammad Gava, a hunter who is secretary of the self-defense Vigilante Group of Nigeria.

"Many of them (Boko Haram) were killed outside the trenches while some fled back," said another civilian fighter, Ibrahim Musa.

"We were with the soldiers during the attack and I was shocked to see that Boko Haram could be in such large numbers," Musa told The Associated Press.

Panicking people took flight, some women hefting babies on their backs while other children clung to their skirts. An elderly woman trying to run had an asthma attack.

The army imposed a 24-hour curfew amid fears some insurgents have slipped through trenches and sand walls constructed to prevent a motorized assault after a Feb. 1 offensive in which the Islamic extremists attacked Maiduguri from four fronts.

The curfew is "to protect lives and property of innocent and law-abiding people of Maiduguri," said a statement from Col. Tukur Gusau, spokesman for the army's 7th Division that is leading the fight against Boko Haram.

A multinational force and Nigerian troops backed by bombing fighter jets and helicopter gunships drove the extremists from all towns in the northeast in a 14-week-long offensive. Nigerian officials have said they have the militants hemmed into their stronghold in the vast Sambisa Forest, which is about 125 miles southeast of Maiduguri.

An offensive on forest camps has freed some 700 girls and women held captive by the extremists. But it appears to be bogged down by militants' land mines and booby traps.

Maiduguri has suffered several attacks, including a March 14, 2014 assault in which Boko Haram invaded Giwa Barracks and freed hundreds of detainees. More than 600 people were killed that day, mostly unarmed detainees gunned down by Nigerian troops, according to Amnesty International.

Maiduguri used to be a city where people didn't lock the doors to their homes. Its population of 2 million has been swelled by more than 300,000 refugees.

More than 1.5 million people in Nigeria have been driven from their homes, some across borders, during the nearly 5-year-old Islamic insurgency. Last year was the bloodiest, with some 10,000 people killed, according to the U.S. Council on Foreign Relations.