Gunmen raided a government secondary school in northern Nigeria's Katsina state, police said on Saturday.
In an apparent kidnapping attempt for ransom, hundreds of pupils may have fled and locals told AFP that several were captured.
President Muhammadu Buhari on Saturday condemned the attack and ordered security reinforcement in other schools.
The gunmen stormed Government Science Secondary School at Kankara late on Friday.
"The bandits came on motorcycles, firing sporadically, and tried to enter the school," state police spokesman Isa Gambo said.
"Our men, with the assistance of the army, engaged them in a shootout lasting one and a half hours."
The gunmen were forced to retreat and were being tracked, but the spokesman made no mention of casualties.
About half of the school's 800 pupils were missing, a parent and school employee told Reuters.
Reinforcements had been sent to search for any missing pupils.
"This morning about 200 students who fled for safety during the assault returned to the hostel," he said.
The police said an inspector was injured and was receiving treatment.
Local residents said several students were kidnapped by the attackers, who split into two groups.
"The kidnappers fought with security personnel," Nura Abdullahi told AFP. "While the fighting was continuing another group went into the school and took away several students.
"Some of the students who escaped returned to the town this morning but others took a bus home.
"The school is deserted. All the students have vacated."
Another resident, Ibrahim Mamman, said most of the pupils had escaped, "but some were captured and taken away by the bandits".
"Nobody can say how many students were abducted because there has not been a headcount," Mr Mamman said.
Local media reported that scores of pupils might have been abducted.
Mr Buhari on Saturday urged security forces to arrest the gunmen.
"I strongly condemn the cowardly bandits' attack on innocent children at the Science School, Kankara," he said.
"Our prayers are with the families of the students, the school authorities and the injured."
Katsina, Mr Buhari's home state, is among several in north-west Nigeria repeatedly attacked by bandits who kidnap for ransom and rustle cattle.
In August, seven students were kidnapped with their female teacher from a private secondary school in nearby Kaduna state.
The hostages were later released but it was not revealed if a ransom were paid.