More than 330 children were missing from the Government Science Secondary School in Kankara after gunmen with assault rifles attacked their school on Friday night.
Nigeria’s Boko Haram jihadist rebels had claimed responsibility for the attack.
A spokesman for the governor of Katsina state, where the boys were kidnapped, told BBC News the 344 pupils had been freed and were in “good condition and expected home within hours”.
The spokesman, Abdul Labaran, said none of the pupils had been killed.
Nigerian presidential spokesman Garba Shehu said in a statement on Monday that “the kidnappers had made contact and discussions were already on, pertaining to the safety and return” of the children to their homes.
Mr Shehu said nothing about the identity of the abductors. Several armed groups operate in north-western Nigeria, where Katsina state is located.
It was originally believed the attackers were bandits, who sometimes work with Boko Haram.
Several armed groups operate in north-western Nigeria, where Katsina state is located.
The most serious school attack took place in April 2014, when more than 270 schoolgirls were abducted from their dormitory at the Government Secondary School in Chibok in north-eastern Borno State. About 100 of the girls are still missing.
Boko Haram said at the time it wanted to stop women from attending schools.
The recent incident at the Government Science Secondary School in Kankara is the worst attack on a boys’ school since February 2014, when 59 were killed during a Boko Haram attack on the Federal Government College Buni Yadi in Yobe State.
Boko Haram and the breakaway faction, the Islamic State West Africa Province, are fighting to impose strict Islamic Shariah rule in Nigeria.
Thousands have been killed in the more than 10-year-old insurgency and more than a million people displaced.
Additional reporting by Associated Press.