A man had to run for his life after following his car's GPS directions onto train tracks in Melbourne's inner-north on Wednesday night.

The 25-year-old man drove onto the tracks at O'Hea Street in Coburg about 10.30pm.

When he realised he was on the tracks he tried to reverse, but his car became stuck.

The man, from Deer Park in Melbourne's west, was then forced to abandon his car and run as a train started approaching.