Julian, Dick, George, Anne and Timmy the dog plan a camping trip to a moor with the absent-minded and insect-loving Mr Luffy, a master at Julian and Dick's school. When they arrive at camp they find that their camping site is close to a farm. They discover several old railway tracks that run under the moors, some of them unused. They soon make friends with a boy named Jock, who lives at the farm with his mother and stepfather (Mrs & Mr Andrews.) While exploring the moor, the five find a railway yard and a tunnel that are apparently abandoned. A watchman called Wooden Leg Sam tells them that "Spook trains" travel along those tracks before chasing them away.
On avisit to the farm the children are surprised to find that most of the farm labourers are not working properly although Mr Andrews, has supplied the farm with a lot of expensive equipment and vehicles. When Mr Andrews hears about the spook trains, he warns the children to stay away from the railway yard, and tries to prevent Jock from meeting the Five over the next few days.
Julian and Dick secretly set off with Jock the next two nights to watch for the spook train, leaving the girls behind. They find that there is indeed a mysterious train coming from and back into the tunnel, infuriating George. Refusing to join the others the next day, she goes off with Timmy to try to find the spook trains by herself. She does find one, which enters a secret area behind a supposedly blocked-off section of the tunnel.
Meanwhile, the boys explore the tunnel while Anne waits outside, but they are captured by some men led by Mr Andrews. Anne runs off to find Mr Luffy, but gets lost on her way. Eventually she does find him, along with some police officers that are helping him search for the missing Five. George, who had been hiding inside the train, rescues the boys, and realising that the train is used for smuggling, they try to find a way out of the tunnel. They are recaptured, but just in time, Anne arrives with Mr Luffy and the police to free them.