Gunmen also set fire to the local government secretariat, police station and a clinic during the attack in the village just 46 miles from Maiduguri, the volatile capital city of Borno state, where the Boko Haram ideology sprang up some four years ago.
Ngubdo Modu, a fruit seller, said he managed to escape by hiding in the bush. He thought the attacks may have been in retaliation for recent arrests of sect members identified by a local vigilante group known as the Civilian Joint Task Force. He said: "I believe we suffered that attack because of how our Civilian-JTF had succeeded in curtailing their atrocities by pointing out some of their members to the security operatives who arrested them recently."
A lack of phone access makes the area a soft target for Boko Haram, a group that wants to impose Shariah law in Nigeria.
Since 2010, more than 1700 people have been killed in attacks by Boko Haram, which means "Western education is forbidden".
State attorney-general Kaka Shehu Lawan and the state police commissioner have visited Gajiram to give condolences to the families of those killed in Wednesday's attack and find out the extent of the damage, a government official said.