MAIDUGURI, Nigeria — Maiduguri, the major city in Nigeria’s northeast, came under sustained attack from Boko Haram terrorists on Sunday, and officials here called it the group’s most audacious assault on the city to date.

By early afternoon, the attackers had been beaten back, but not before dozens of soldiers had been killed, officials said. They said the insurgents had taken a major military base to the north of the city, sending about 1,400 soldiers fleeing into the bush.

The attack on this city of more than two million people, a commercial and administrative hub, began late Saturday when the militants from the Islamist insurgency rushed in from at least two directions. Loud explosions could be heard in the center of the city, as well as small-arms fire and artillery in its suburbs. The attack was a significant thrust forward in a creeping campaign that began last summer to encircle Maiduguri, officials said.

“Certainly this is the most serious attack yet,” said Kashim Shettima, the governor of Borno State, of which Maiduguri is the capital. “We faced a really existential threat.”