A train crash at a railway station in Indonesia has killed at least 36 people and injured more than 40.

The crash happened at 3am local time when a train from the capital, Jakarta, ploughed into the rear of a stationary train at a station in Petarukan, a coastal city in Central Java province.

It took almost an hour for rescue workers and ambulances to arrive. Rescuers then spent several hours searching through the wreckage for trapped survivors of the crash, which knocked several carriages off the track and littered the area with debris.

"Bloody corpses were hanging from the carriages," said Anwar Sumarno, a 24-year-old university student who had been sitting near the front of the stationary train.

"The injured were screaming in the darkness, but there was nothing we could do," he said. "Everyone was in a state of shock."

Residents helped police and rescue teams retrieve the bodies of those killed and carry survivors to stretchers. Many of those hurt in the crash, including several children, suffered severe injuries and broken bones.

By early this afternoon, only one body was still trapped inside an up-ended carriage, according to a rescue worker. Thirty-five other bodies were taken to three nearby hospitals, said Tri Yuniasari, a spokeswoman for the Hasyim Ashari hospital.

Among the victims were Bayu Sakti, a 33-year-old army sergeant, his wife, 29, and their four-year-old son.

"It'd been six months since they'd come home," Bayu Sakti's 60-year-old mother, Agatha, told the news website Detik.com. "We were waiting for them."

More than 40 people were hurt, including several children, health officials said. Some had severe injuries and broken bones.

Cranes were used to remove some of the heavy wreckage.

Investigators are trying to determine if human error or a mechanical failure was to blame.

A transportation ministry spokesman, Bambang Ervan, said: "We're checking to see if the signals of the parked train were working properly."

The crash is the latest in a run of plane, train and ferry accidents in Indonesia in recent years that have killed hundreds. The country has a poor reputation for safety standards and maintenance.

Just an hour after the collision in Petarukan, another train crashed in the town of Solo, also in Central Java, killing at least one person.