The girls were abducted by unidentified gunmen from their boarding school in Jangebe, Zamfara state, on Friday and taken to a forest, police said.
The state’s governor said on Tuesday that the group had been freed and the girls were now safe.
Such kidnappings are carried out for ransom and are common in the north.
Dozens of the girls were seen gathered at a government building in Zamfara after they were taken there in a fleet of mini-buses.
“It gladdens my heart to announce the release of the abducted students… from captivity,” Governor Bello Matawalle wrote on Twitter.
“This follows the scaling of several hurdles laid against our efforts,” he added. “I enjoin all well-meaning Nigerians to rejoice with us as our daughters are now safe.”
The authorities said 279 girls had been freed, adding that a figure given last week by police that 317 had been kidnapped was no longer accurate.
One official told Reuters news agency that the discrepancy was because of the fact that some girls had fled shortly after being abducted.
“Most of us got injured… and we could not carry on walking,” one of the girls told the BBC.
“They said they [would] shoot anybody who did not continue to walk,” she added. “We walked across a river and they hid us and let us sleep under shrubs in a forest.”
The group’s release was secured through negotiations between government officials and the abductors, authorities in Zamfara state told the BBC.
Mr Matawalle has denied paying for the girls to be released, but last week President Muhammadu Buhari admitted state governments had paid kidnappers “with money and vehicles” in the past and urged them to review the policy.
President Buhari said he felt “overwhelming joy” at the news of the girls’ release. “[I am] pleased that their ordeal has come to a happy end without any incident,” he said.
The 2014 kidnap of 276 schoolgirls in the north-eastern town of Chibok by Islamist militants Boko Haram brought global attention to the scourge of raids on schools in Nigeria, but a surge in recent attacks is suspected to be the work of criminal gangs.
The raid in Zamfara state was the region’s second kidnapping in recent weeks. Some 27 students were kidnapped from a boarding school in Kagara in the north-central state of Niger last month before they were released on 17 February.
No group has said they were behind the Zamfara kidnappings.
Armed groups operating in the state often kidnap for ransom but when gunmen took more than 300 boys from Kankara in neighbouring Katsina state in December last year, some reports said Boko Haram, which operates hundreds of miles away in the north-east, was behind the attack.
The reports were later disputed and the boys released after negotiations.