Islamist Boko Haram militants disguised as preachers killed at least 24 people and wounded several others in an attack near a mosque in northeast Nigeria's Borno state, a military source and witness said on Monday.

The attackers arrived in cars late on Sunday and gathered people at a mosque in the remote village of Kwajafa, pretending to preach Islam. They then opened fire on them, witness Simeon Buba said.

The group's six-year insurgency, and President Goodluck Jonathan's failure to end it or protect civilians, were factors in the victory of opposition candidate Muhammadu Buhari in last week's election.

The group fighting for an Islamic state has killed thousands and kidnapped hundreds, although a military operation against them by Nigeria and neighbors Chad, Cameroon and Niger in the past two months has wrested back much of the territory it controlled.

"People didn't know the Boko Haram men came for attack because they lied to our people that they came for preaching," said Buba in a telephone conversation.

"They opened fire on them and killed many people," he said, adding that houses were set on fire.

Some people were being treated for gunshot wounds and burns at a hospital in the Borno state town of Biu on Monday, a source there said.