The man drove the locomotive at full speed for 35km before officials derailed it and averted a possible disaster late on Tuesday, police in the southern city of Karachi said.
Irshad Beg, a railway police official, identified the arrested man as Madan Lal, who is in his 50s.
"We suspect that he stole the engine and drove it on the track to cause a terrorist attack," Beg said.
Lal's apparent target was a regular passenger service that was on the same track before it was diverted, the police official said.
Two Pakistani men, a driver and a fireman, were also arrested for negligence, Beg said.
Lal told AFP in custody that he was a Pakistani citizen and stole the engine just to have a ride on the track. He refused to answer other questions.
Beg said the suspect would be produced before a local court and a thorough medical examination may be conducted to determine his mental health.
"He does not have anything to prove that he is a Pakistani citizen and we suspect him to be from the Indian state of Hyderabad," Beg said.