A tour bus carrying a group of junior high school students, their parents and teachers crashed into a ravine in Indonesia - killing at least 27 passengers and injuring 39 others.

Police and rescue workers said Thursday the bus plunged into the ravine after its brakes malfunctioned. It was traveling from the west Java town of Subang on a winding late Wednesday night.

Local police chief Eko Prasetyo Robbyanto said the bus was on its way back from Subang from a pilgrimage site.

The driver lost control of the vehicle before it dropped into the 20-meter-deep ravine.

Investigators said survivors confirmed that the vehicle's brakes had malfunctioned.

Rescuers spent the entire night pulling survivors from the wreckage. They used cranes to lift parts of the wreckage to get to trapped survivors.

Bandung search and rescue agency chief Deden Ridwansah said it had recovered 27 bodies. He said that 39 people have been taken to nearby hospitals. On Thursday morning, rescuers were able to recover the body of a young boy trapped under the wreck.

Ridwansah said that 13 of those rescued suffered serious injuries. The driver of the vehicle was killed.

Workers from the National Search and Rescue Agency along with local police were at the scene following the accident. Local news media released film of the workers evacuating some of the injured.

Thursday's accident was one of the deadliest in recent years. An accident involving a bus in December 2019 killed 35 people when a bus fell into an 80-meter-deep ravine and into a river on Sumatra.