"The abducted students, staff and relatives of Government Science College Kagara have regained their freedom and have been received by the Niger state government," Niger state governor Abubakar Sani Bello said on Twitter.
In mid-February, gunmen in military uniforms raided the college, killing one student and taking 42 others -- including 27 schoolboys, three teachers and other relatives of school staff, officials said.
Northwest and central Nigeria have seen a surge in attacks by heavily armed criminal gangs locally known as "bandits" who raid villages, killing and abducting residents after looting and torching homes.
On Friday, in the Jangebe, a village in Zamfara state, a suspected criminal gang attacked the Government Girls Science Secondary School in the country's third school attack in less than three months -- a series that has revived traumatic memories of the "Chibok girls" kidnapped by extremists nearly seven years ago.
Zamfara State Police Command, working with the military, "commenced a joint search and rescue operations with a view to rescuing the 317 students", police spokesman Mohammed Shehu said.
The situation in Jangebe was tense as local people vented their anger on journalists, security personnel and officials who arrived in the village.
Nigerian President Muhammadu Buhari condemned the latest kidnapping as "inhumane and totally unacceptable".
"This administration will not succumb to blackmail by bandits who target innocent school students in the expectations of huge ransom payments," he said in a statement on Friday.
"We have the capacity to deploy massive force against the bandits in the villages where they operate, but our limitation is the fear of heavy casualties of innocent villagers and hostages who might be used as human shields by the bandits."
"Our primary objective is to get the hostages safe, alive and unharmed," he added, according to AFP.