DAKAR, Senegal — Dozens of gunmen attacked an agricultural college in northeastern Nigeria late Saturday and early Sunday, killing more than 40 students, local officials said. The attackers were thought to belong to the extremist group Boko Haram.

The attackers drove into the campus of the Yobe State College of Agriculture, in a rural area just south of Damaturu, the state capital, survivors said. A student, Musa Aliyu, 21, said on Sunday that the attackers had entered the college’s dormitories as students slept, and then opened fire randomly in the darkness.

The attack was the second large-scale massacre of civilians attributed to Boko Haram in less than two weeks. The Nigerian military has been pressing a scorched-earth counterinsurgency campaign against Boko Haram for four months, and appeared to have halted its attacks in the urban centers of northeastern Nigeria, while hundreds of civilians fled into neighboring Niger to escape the violence. In rural areas, though, killings by the group — including at least 143 reported deaths in the northeastern town of Benisheik on Sept. 17 — appear to be continuing unabated.

In its war against the Nigerian state, Boko Haram has singled out government institutions, especially schools, for attack. One of its tenets is that Western-style education, not based on the Koran, in conventional schools is sinful and un-Islamic; the group has burned numerous schools in Maiduguri, the largest city in the region, and in early July it attacked a government secondary school in the town of Mamudo, killing 42 people, mostly students.