A driver had a narrow escape after his car plunged 10 metres down an embankment onto railway tracks and into the path of an oncoming freight train in the Blue Mountains.

The man was driving along a railway service road at Blaxland, west of Sydney, about 9:00pm (AEDT) last night, when his vehicle fell off a cutting and landed on the tracks.

The driver, aged in his 20s, managed to scramble from the vehicle before it was hit by a freight train and dragged 40 metres.

Inspector Peter Balatincz from Springwood Police says he was extremely lucky.

One local resident heard the crash and was surprised the man survived.

"I don't know how the bloke got out OK but apparently he's fine - a miracle," he said.

The man was treated by paramedics at the scene before being taken to hospital with non-life threatening injuries.

Police say the two train drivers were not injured in the accident.

The train line between Penrith and Springwood was closed for several hours as fire crews worked to remove the wrecked car.

The lines have since reopened.