The Yauri incident is the seventh mass abduction from a school in Nigeria this year.
Five teachers and the vice-principal are also missing and most of the kidnapped students are female, said a student who had been abducted and was later released. He insisted on anonymity for his safety.
The gunmen released the student because he had a gunshot wound and was losing a lot of blood. He was shot through a window by the attackers who forced their way into a building where some students were hiding.
The Nigerian Army said Friday it had rescued two teachers and five of the students “after a fierce exchange of fire with the criminals.”
Military spokesman Brig. Gen. Onyema Nwachukwu said in a statement that “troops in conjunction with elements of the Nigerian Air Force, who provided close air support,” intercepted the gunmen early Friday “and engaged them in a firefight leading to the successful rescue of the teachers and students.”
The troops are still pursuing the kidnappers to rescue the remaining students, he said, adding that one female student had died of exhaustion.
In an earlier kidnapping, a student was shot dead on June 11 at the Nuhu Bamalli Polytechnic in Zaria by gunmen who abducted eight students and two lecturers.
Last month, 147 students and three teachers were abducted on May 30 from the Salihu Tanko Islamic School, Tegina, in neighboring Niger State. One person was shot dead during that incident.
The abductions are being carried out by armed groups who want ransoms. Many schools have been forced to close as authorities are unable to adequately protect them.
The spate of mass abductions from schools in Nigeria has grown significantly since 2014 when members of the Jihadist group Boko Haram abducted 276 female students from a school in Chibok in Borno State.