A naked trespasser has caused disruption to train services through Edinburgh Waverley and Haymarket.
British Transport Police said officers responded to reports of a man "trackside" at Waverley Station "heading towards the castle".
ScotRail said he had been removed from the railway line and it was working to restore services as quickly as possible.
Pictures on social media showed a naked man near the tracks.
British Transport Police later tweeted that the man had been detained, was safe and was being provided with medical support.