British Transport Police (BTP) said yesterday the youngsters, believed to be aged nine or ten, were seconds from being struck by a train travelling at speed through Wester Hailes station.
The incident is among at least five involving children crossing tracks at the station in the last three months.
Others included four boys, aged between five and ten, who were caught on CCTV on 1 May.
The near-miss, involving a First TransPennine Express train from Edinburgh to Manchester Airport, happened at about 4:15pm on 13 April.
BTP said other incidents at the station, which has not previously been a troublespot, involved groups of up to four children, aged between seven and ten. Most were boys, but two involved ten-year-old girls.
BTP said it had stepped up patrols and visited local schools.
Constable Niall Bonnar said: “Children, mostly young boys, have been captured on CCTV running between the platforms at the station, and astonishingly back again, as well as walking off the end of the platforms.
“It is enormously worrying that primary-age children are putting themselves in grave danger by trespassing. The children seem to be oblivious to the risks that trespassing and playing near the railway presents.
“They also seriously endanger the safety of others working, and travelling on the railway, and the foolishness of their actions cannot be underestimated.”
There have been some 120 trespass incidents across Scotland in the last three months, and more than 900 in 2013-14.
Some 24 people a year are killed on Scotland’s railways, although these include suicides.
Train drivers union Aslef said drivers should talk direct to schoolchildren again about the dangers. Scotland district secretary Kevin Lindsay said: “Aslef is fully supportive of Network Rail and ScotRail in warning children that the railways are a dangerous place to play.
“However, warnings are not enough. In years gone by, train drivers gave talks to school children directly. It’s time for these school visits to be reinstated.
“We must ensure children understand the risks and dangers of going near the railway”
Child protection charity Children 1st urged anyone seeing youngsters on the tracks to take action.
Chief executive Alison Todd said: “We believe everyone is responsible for children’s safety. Children can’t be supervised at all times every day, and it’s important that they develop the freedom to explore in a safe way.
“However, trespassing on the railway is incredibly dangerous. We would encourage any adults to look out for children if they see them engaged in any behaviour which puts them at risk.
“If you have an immediate concern, please don’t turn a blind eye – speak to the children involved if you feel you can, or contact the police.”
A spokeswoman for the new ScotRail-Network Rail alliance said: “We do not tolerate crime of any kind, and fully support the efforts of the BTP.”