Maiduguri would be a major prize for Boko Haram
Nigerian Islamist Boko Haram fighters have attacked the strategically important north-eastern city of Maiduguri, with dozens reported dead.
Earlier on Sunday they captured the north-eastern town of Monguno.
The BBC's Will Ross in Lagos says that with the insurgents gaining ground, Maiduguri is increasingly at risk.
US Secretary of State John Kerry meanwhile has arrived in Nigeria to call for peaceful elections next month which need to set "a new standard".
The vote looks set to be the closest since the end of military rule 15 years ago.
Our correspondent says that Mr Kerry is in Nigeria to show solidarity in the fight against Boko Haram, which has increased its attacks in recent days.
The BBC's Will Ross in Nigeria's commercial capital Lagos:
People in Maiduguri woke up to the sound of explosions and heavy gunfire as Boko Haram launched a pre-dawn attack on this strategic city.
Ground troops, air strikes and local vigilantes managed to stop the jihadists from penetrating the city. Much of the fighting was around a barracks.
In a separate attack the town of Monguno was captured - the latest to be seized by the group.
With the insurgents gaining more and more territory Maiduguri is increasingly vulnerable. It is home to tens of thousands of people who have fled their homes because of the conflict.
Fierce fighting has been reported on the outskirts of Maiduguri. A curfew remains in place and dozens of militants and soldiers are reported to have been killed.
Human rights group Amnesty International has warned that hundreds of thousands of civilians are now "at grave risk''.
The streets of Maiduguri were almost deserted after the imposition of a curfew on Sunday
The attack on Maiduguri coincided with a visit by US Secretary of State John Kerry (centre) to Lagos for meetings with President Goodluck Jonathan (right)
Militants also attacked Monguno, 140km (86 miles) north of Maiduguri. The army there was reported to have been overwhelmed, with houses set on fire.
A journalist in Maiduguri told the BBC that fleeing soldiers from Monguno were now arriving at the barracks in in Maiduguri.
Boko Haram, which means "Western education is forbidden" in the Hausa language, launched guerrilla operations in 2009 to create an Islamic state.
Thousands of people have been killed throughout the insurgency, mostly in north-eastern Nigeria.
In his Lagos talks, Mr Kerry urged President Goodluck Jonathan and the main opposition's presidential candidate, former military ruler Muhammadu Buhari, not to condone violence during what is expected to be a tense election campaign,
"We are prepared to do more [to counter the Boko Haram threat] but our ability to do more will depend to some degree on the full measure of credibility, accountability, transparency and peacefulness of this election," Mr Kerry said.