GUSAU, Nigeria, March 2 (Reuters) -- Gunmen have freed all 279 girls kidnapped from a boarding school in northwest Nigeria, officials said on Tuesday, as victims described how their abductors had beaten and threatened to shoot them.

The pupils from Jangebe, a town in Zamfara state, were abducted just after midnight on Friday. All had now been freed, Zamfara Governor Bello Matawalle said.

Umma Abubakar, among those released, described their ordeal.

"Most of us got injured on our feet and we could not continue trekking, so they said they will shoot anybody who did not continue to walk," she told Reuters.

Boarding schools in northern Nigeria have become targets for mass kidnappings for ransom by armed criminal gangs, a trend started by the jihadist group Boko Haram and continued by its offshoot, Islamic State West Africa Province.

Friday's raid on the Government Girls Science Secondary School was the second such abduction in little over a week in the northwest, a region increasingly targeted by gangs.

Governor Matawalle said "repentant bandits" working with the government under an amnesty program had helped secure the Jangebe girls' release.

"Those repentant ones are working for us, and they are working for the government and they are working for security," he said.

Initial reports put the number kidnapped at 317, but Zamfara government spokesman Sulaiman Tanau Anka said the total was 279, as some of the girls had run into the bush at the time of the raid.

'THEY HIT US WITH GUNS'

Reuters journalists in Zamfara's state capital, Gusau, saw dozens of girls in Muslim veils sitting in a hall in a state government building. A few parents arrived, and one father wept with joy after seeing his daughter.

Most of the girls appeared unharmed, but at least a dozen were sent to hospital.

Farida Lawali, 15, told how she and the other girls had been taken to a forest by the kidnappers.

"They carried the sick ones that cannot move. We were walking in the stones and thorns," she said, sitting in the government house building, covered in a light blue veil.

"They started hitting us with guns so that we could move," she added. "While they were beating them with guns, some of them were crying and moving at the same time."

President Muhammadu Buhari, who met his top security officials on Tuesday, said news of the girls' release brought "overwhelming joy."

He warned against paying ransoms to kidnappers, which the national government has denied doing.

"Ransom payments will continue to prosper kidnapping," Buhari said, urging the police and the military to bring the kidnappers to justice.

One father, whose seven daughters were among those kidnapped and freed, said the incident would not deter him from schooling his children.

"It's a ploy to deny our girls ... from getting the Western education in which we are far behind," Lawal Abdullahi told Reuters. "We should not succumb to blackmail. My advice to government is that they should take immediate precautions to stop further abductions."

The U.N. children's agency UNICEF urged the Nigerian government to protect schools so children will not be fearful of going to school, and parents afraid of sending their children to school.

As recently as Saturday, gunmen released 27 teenage boys who had been kidnapped from their school on Feb. 17 in Niger state.

In 2014, Boko Haram abducted more than 270 schoolgirls from the northeasterly town of Chibok, in Nigeria's most high-profile school kidnapping. Around 100 remain missing.