Army commandos using helicopters and a makeshift chairlift have rescued eight people from a broken cable car dangling hundreds of feet above a canyon in a remote part of Pakistan.

The six children and two adults became trapped earlier in the day when one of the cables snapped while the passengers were crossing a river canyon in the Battagram district in Khyber Pakhtunkhwa province. The children had been on their way to school.

Caretaker Prime Minister Anwaar-ul-Haq Kakar congratulated the military and other rescuers for the success.

“Relieved to know that … all the kids have been successfully and safely rescued,” Mr Kakar said on Twitter, the service now rebranded as X. “Great team work by the military, rescue departments, district administration as well as the local people.

Because helicopters could not fly after sunset, rescuers eventually shifted from an airborne effort to a risky operation that involved using one cable that was still intact to approach the car with the chairlift.

The cable car dangles hundreds of feet above the ground while it is circled by a helicopterThe cable car dangles hundreds of feet above the ground while it is circled by a helicopter (AP)

Footage on TV stations showed a child in a harness being pulled to safety. The commandos’ rope could be seen swaying in the wind against the mountainous landscape.

An expert described the helicopter rescues as extremely delicate because the wind generated by the helicopter blades could further weaken the remaining cables holding the car aloft.

Relatives of those trapped prayed for more than 12 hours while anxiously watching the operation unfold. The rescue also transfixed the country as Pakistanis crowded around televisions in offices, shops, restaurants and hospitals.

As the rescued children were handed over to their families, most burst into tears, said Nazir Ahmed, a senior police officer who was present in the area where the air and ground rescue mission was launched.

“Everyone was praying for this moment,” he said.

People watching a news channel covering the rescue operationPeople watching a news channel covering the rescue operation (AP Photo/Muhammad Sajjad)

Bilal Faizi, a spokesperson for the state-run emergency service, said food and water were supplied to the car earlier in the day.

According to Pakistani TV stations, some of those who had been trapped were in contact with their families by mobile phone.

Villagers frequently use cable cars to get around Pakistan’s mountainous regions. But the cars are often poorly maintained, and every year people die or are injured while travelling in them.

Helicopters were sent to attempt to pluck the people from the cable car but only after the group spent six hours precariously suspended 1,150 feet above ground, according to Taimoor Khan, a spokesman for the disaster management authority.

Pakistan’s caretaker prime minister, Anwaar-ul-Haq Kakar, wrote on Twitter, the service now rebranded as X, that he had ordered safety inspections of the country’s cable cars and chairlifts.

In 2017, 10 people were killed when a cable car fell into a ravine hundreds of feet deep in the popular mountain resort of Murree after its cable broke.