This killed at least 24 security personnel, security sources and a witness said.
The attack late on Monday in Yobe state occurred not far from where the Islamist insurgents shot or burned to death 59 pupils at a boarding school in February.
A witness and resident of Buni Yadi, who identified himself only as Mustafa for fear of retribution, said the militants arrived in an armoured personnel carrier and six Hilux trucks before dismounting and firing into the air.
The witness, and two security sources, one in the Yobe state capital of Damaturu and another at the army’s northeast headquarters in Maiduguri, said that at least 11 soldiers and 14 policeman were killed. The security source in Damaturu state said 17 soldiers may have actually died.
In what has become rare for a movement that has often killed civilians, Boko Harm called out to people on the street not to run away as they had only come for the security forces, according to Mustafa and the Yobe police source said.
The insurgents also burned down the police barracks, the army base, the high court and the residence of the district head Abba Hassan.
Boko Haram, whose violent struggle for an Islamic state in northern Nigeria has killed thousands and made them the biggest threat to security in Africa’s top oil-producing state, are still holding more than 200 girls kidnapped on April 14.