Train passengers in Greater Manchester faced disruption to rail services while police dealt with a man on a viaduct in Stockport.
British Transport Police said its officers were called to reports of a man on the track at 05:30 BST on Thursday.
Some lines between Manchester Piccadilly and Stockport were blocked and subject to delays.
It took emergency services almost 24 hours to bring the man to safety.
Network Rail said the line was cleared at 04:20 BST and British Transport Police Greater Manchester later tweeted that the "trespass incident" at Stockport was "resolved".
"We would like to thank the public for their support and understanding as we tried to bring the man to safety as quickly as we could," Network Rail added.
The incident led to significant disruption with some trains diverted.
Virgin Trains, which operates services between Manchester and London Euston, did not serve Stockport and Macclesfield stations while the incident was ongoing and instead ran a bus service between Macclesfield and Wilmslow.
Trains are now running as normal.