Police and train operators are investigating after two teenagers were spotted standing on the tracks filming a train coming towards them.
ScotRail confirmed it is looking into the incident which took place close to the Maltings Crossing in Carnoustie last week.
Meanwhile, British Transport Police is appealing for anyone who has any information about the trespassing to come forward.
Witness Tanya Alavuk, 48, alerted a nearby police officer after spotting the teenager on the tracks on Thursday.
She said: “I couldn’t believe what I was seeing. It was horrifying.
“This boy was standing on the railway line filming the train that was coming towards him.
“The train driver had obviously seen him too and managed to slow the train down.
“The boy then stepped to the side and let the train pass.
“I was with a friend and we initially thought that someone was about to jump in front of the train.
“We didn’t know what to do but we saw police officers close by and ran to alert them.
“They gave chase but the boy and another small group of young people ran away.
“I dread to think what could have happened.”
A spokesman for British Transport Police said a wheelie bin was also removed from the tracks.
He said: “Officers were called to Carnoustie station at 7pm on Thursday February 21 following reports of two trespassers on the line.
“BTP quickly attended but two young men had left the scene. A wheelie bin was removed the tracks.
“Inquiries are currently ongoing. Officers would encourage anyone who saw what happened or has any information to contact them by texting 61016 or calling 0800 40 50 40 quoting reference 567 of 21/02/19.”
A spokesman for ScotRail said the driver of Edinburgh to Aberdeen service reported trespassers on the line near Carnoustie shining a torch.
He said that the trespassers ran off as the train approached. The train was subsequently delayed by around 20 minutes as a wheelie bin had to be removed from the line.
“We take this opportunity to remind people not to trespass anywhere on the railway as they put themselves and others at risk of serious injury.”
Carnoustie councillor Mark McDonald said: ““The reports of teenagers on the track at Carnoustie Railway Station is deeply concerning and their actions go far beyond antisocial behaviour.
“Trespassing on a railway line is incredibly dangerous, not only putting their lives in danger but also putting passengers and staff on the train at risk.
“I would urge anyone with any information to get in touch with the British Transport Police.”