2587 AD. Benny and Jason are on the planet Youkali, unearthing relics of an alien civilisation and helping to spread campfire tales about the ghost of a missing student, when Benny is contacted by someone who has recognised her last name -- someone who knew her father, and was present during the battle in which he supposedly turned and ran from the enemy. Former Spacefleet Admiral Sarah Groenewegen has never believed that Isaac would do such a thing, and she gives Benny the flight recorder of her ship, which she had kept as a souvenir. It certainly seems to show Isaac turning and leaving in the midst of the battle, and Benny, determined to learn the truth at last, calls on the Doctor to take her back to see for herself. The Doctor agrees to take Benny back to watch the battle, but insists upon accompanying her in case she is tempted to save her father’s life.
The TARDIS materialises in what the Doctor believes to be an unoccupied area of Isaac’s ship, but he and Benny step out of the TARDIS right in front of Isaac. Fortunately, Benny looks so much like her mother that Isaac assumes they are hallucinations caused by the Daleks’ weaponry -- particularly when a sailing yacht appears floating in space on the viewscreen. Isaac orders his crew to slingshot around a nearby moon in order to come up on the Daleks from behind, and, realising that this is why he appeared to be running away, the Doctor and Benny return to the TARDIS to watch the rest from safety. There, they see a time rift open up and swallow Isaac’s ship before it can return to the battle. The Doctor pilots the TARDIS into the rift, following the fighter’s transponder signal, and much to his surprise, he arrives in Little Caldwell, a quiet English village, in the year 1983. He and Benny head for the nearby occult bookshop and coffee bar to plan their next move -- and find the counter attendant to be Isaac Summerfield, twenty years older than when they last saw him.
As Benny and her father try to deal with their reunion, the Doctor returns to the TARDIS to fetch Roz, Chris and Jason, only to find that it is under observation by people using communicators which have not yet been developed on Earth. And not all of the people are human. Isaac and his crew have been stuck in the twentieth century for two decades, and have used future technology to set up an underground railroad to evacuate aliens stranded on Earth. In doing so they have heard a lot about the Doctor, who is in many cases responsible for the aliens’ being stranded in the first place. Realising that he is regarded with mistrust and suspicion, the Doctor goes for a walk in the woods so as not to spoil Benny’s reunion. In the ruins of an old barn, he meets ghost hunter Ellen Woodworth, who claims to be on the trail of something, but while talking with her he realises that she in fact fears ghosts and only seeks to understand them so she can defend herself against them. Benny then calls him back to Little Caldwell, where a crisis has arisen -- one of two Lacaillans who were due to return home tomorrow has vanished without a trace.
Roz and Chris help Isaac’s team in the search, and meet the others: the psychic Mrs Randrianasolo; Joel Mintz, a young man who was somehow transported back in time from the 1990s; a fifties greaser named Albinex; and Tony the chef, actually a Tzun deserter named M’Kabel. They are unable to find any trace of Ia Jareshth, and the Doctor, realising that Isaac still doesn’t trust him, comes to suspect that she fled out of fear of what the others had said about him. Jason is also upset, but for more personal reasons; Benny has found her lost father, and he’s a hero, but in this very year, 1983, Jason has just been born to an abusive father who will eventually drive him to a life on the streets.
That night, the Doctor senses Mrs Randrianasolo trying to read his mind, and when he wakes up the next morning the TARDIS is missing. He decides to leave the village, and tells Isaac that he’s been looking in the wrong place for his missing alien. Isaac, accepting that the Doctor is telling the truth, sends his team to Greenford Common, where women have camped out to protest the presence of an American cruise missile base and where a slightly unusual woman trying to hide out may pass unnoticed. Joel drives the Doctor to a neighbouring town, where he intends to stay out of the way until Ia Jareshth believes that it’s safe for her to return. But on his way back, Joel is forced off the road by a helicopter and pursued into the woods by soldiers.
The Doctor is kidnapped by two Caxtarids, who give him a truth drug and question him about his time with UNIT and his access to classified data about the era’s nuclear weapons. They seem to be taking this very personally, and the Doctor realises that they blame him for interfering with the politics of their homeworld. However, he insists that the biological weapons their government had developed would have wiped out all life had they been used -- as indeed they did. Under the influence of the drug, the Doctor admits that he failed to destroy them all; in two years’ time the government will release a viral cache to end a rebellion, and the entire Caxtarid civilisation will be destroyed.
The furious Caxtarids are attacked by a ghost, a young woman unfocussed in Time whose touch reveals their future to them, and as they flee she begs the Doctor for help. The Doctor passes out, but is located by Isaac and Benny, who have followed the trail of disturbances and have heard that soldiers arrested the Caxtarids, “a pair of panicking punks with shining red hair.” The Doctor returns to Little Caldwell, where he reveals to Benny that the ghost of Youkali is real; the missing student stumbled across an ancient time-travel device, released its stored charge and was misphased out of her proper place in Time. The ghost followed the trail of the TARDIS to Earth, seeking help -- but while it would be a simple matter for the Doctor to save her with the TARDIS, there is nothing he can do without it. And to make matters worse, now Jason is missing as well.
Joel manages to contact Tony and reports that he’s being hunted by soldiers, and Chris is captured while trying to help him escape. Joel and Tony escape and return to Little Caldwell, where Isaac and the Doctor finally agree to work together to solve what appears to be a mutual problem. The truth is revealed by an unexpected ally -- Graeme the sentient Auton spatula, who spots Woodworth snooping around the shop and stows away in her rucksack. Woodworth, convinced that she has located a nest of alien infiltrators, returns to the military base where the concussed Chris is being given a thorough medical examination prior to interrogation and dissection. Graeme telepathically contacts Tony, and the Doctor and his companions join Isaac and his team on a raid.
The Doctor recognises Woodworth’s base as the same building where he was held captive by Hamlet Macbeth in 1968; Woodworth is a former C19 employee who somehow escaped the purges of that organisation, and she firmly believes that she is acting to keep the world safe from hostile alien invaders. She has already dissected Ia Jareshth and the Caxtarids, and is about to do the same to Chris when the Doctor arrives. He is furious and demands to know why she interrogated and vivisected her captives rather than just talking with them, but eventually realises that she is beyond reason. He thus turns her over to Isaac, contacts his friends at UNIT and burns the house down. Isaac takes Woodworth back to Little Caldwell for interrogation, but she eventually makes a break for it, only to be caught and killed by an Ogri posing as a tombstone in the local cemetery.
There is still no sign of Jason or the TARDIS. The Doctor, unsure whether the arrival of the ghost is a coincidence, builds a ghost detector to try to track her down, and accompanies Isaac and his team when the Lacaillan rescue ship arrives to collect the survivor, Myn Jareshth. Before the Lacaillans arrive, however, a sailing yacht appears in mid-air, transports the Doctor aboard and vanishes -- and Benny recognises it as the ship that appeared on Isaac’s viewscreen during the battle with the Daleks. Aboard the yacht, the Doctor is held captive by Albinex, who reveals himself to be a Navarino with a vicious streak; unlike the rest of his easy-going race, he wants to restore his planet’s warrior past, and has a plan to do so. He forces the Doctor to check on the repairs to his yacht’s time engines while plotting to extract the information he needs about the Destructor Codes. While studying the equipment, the Doctor is reunited with Jason, who was aboard the TARDIS when Albinex stole it and has been hiding on the yacht ever since. The Doctor explains that he once helped UNIT to deal with terrorists who had seized the Destructor Codes, the firing information for every nuclear missile in the world. Albinex apparently wants to pick them out of his memory for reasons the Doctor can only guess at... but the recent arrival of missiles at the American base can’t be a good sign.
The Doctor uses the damaged time engines to generate a gateway back to the coffee shop, which collapses after he and Jason pass through. There, he learns that Roz, Chris and Joel have been having visions of possible futures during encounters with the ghost, who is contacting time travellers in a desperate attempt to find someone who can help her. Before he can deal with this, Albinex sends the Admiral a video in which he reveals that he has kidnapped the Doctor’s former companion Ace, and demands that the Doctor give himself up. Isaac insists upon accompanying the Doctor to the rendezvous with his team, but upon arriving they are attacked by the feral Ace -- and a feral Doctor. They are forced to kill the attackers in self-defence, and the Doctor realises that these are shape-shifting demons from the Troifran experiment on Tir na n-Og, whom Albinex must have captured and stored in cryogenic stasis until he needed them. The team tries to capture Albinex, but he flees -- and to the Admiral’s shock and fury, he shoots Joel in the shoulder as he goes, seriously wounding him.
The Doctor, unwilling to let anyone else get injured for his sake, tracks down the yacht via sightings reported on Joel’s BBSes and sets off to confront Albinex. M’Kabel insists upon accompanying him, and the Doctor allows him to come along though well aware that M’Kabel is leading him into a trap and is not working directly for Albinex. Once the Doctor is back aboard the yacht, Albinex reveals that the ghost has contacted him, and that he’s promised to help her if she helps him. The ghost has thus stretched herself further out of phase, and she tries to force the Doctor back through his history to read the Destructor Codes. She is unable to get past the pain of his most recent regeneration, for which his previous incarnation still hasn’t forgiven him, and she therefore tries pushing forward to show the Doctor the circumstances of his next regeneration -- he will die alone, surrounded by well-wishing strangers who are unable to save him. He still refuses to give in, but the ghost locates a moment of pleasure in his life and amplifies the sensation a million times, finally breaking him. He gives the Destructor Codes to Albinex, who takes the Doctor to the airlock -- and although M’Kabel had been told to keep him from harming the Doctor, he is unable to prevent Albinex from flinging the Doctor out of the airlock, thirty metres above the surface of a lake.
Benny and Isaac track down the Doctor with the ghost detector and return him to Little Caldwell, where he tells Isaac that he knows the truth; Albinex and M’Kabel are working for him. Isaac admits that he’s right, but that Albinex was told not to harm the Doctor -- and realises too late that Benny has heard him. Isaac explains to the stunned Benny that Albinex’s ship was damaged when he was caught up in the battle with the Daleks, creating the temporal rift that drew them all back to the 20th century and giving Isaac the chance to do something positive about the Dalek menace. With the Destructor Codes, Isaac intends to start a limited nuclear war; instead of a century of peace, the Earth will remain on a military footing, capable of defending itself against the Dalek invasion of the 22nd century. This is why Isaac waited until now, when the cruise missiles have arrived, to activate the transponder signal that the TARDIS -- and presumably Woodworth -- followed to Little Caldwell. But now Benny has something to tell him, about how she saw her mother killed by a Dalek bombardment when she was still just a child, and how she’s always known deep down that her father would betray her, because he never came back for her. Isaac retreats to the coffee bar, trying to pull himself together and carry on, but the Doctor follows and warns him that there are too many variables in his plan. The Doctor is an expert at changing history, and knows that one slight deviation could destroy everything that Isaac hopes to achieve. He’s seen Albinex’s time engines, and knows that they’re damaged beyond repair; he’s been lying to Isaac all this time, and thus must have an agenda of his own.
Isaac’s army is awaiting his marching orders, and now he is forced to tell them that they must abandon the plan they have worked on for the past twenty years. The Doctor stands by him, and although some of the aliens refuse to work beside the man who stranded them here, many others agree to fight alongside him to save the Earth from Albinex. The Ogrons, however, have gone, leaving behind a print-out of orders in the written language of the Daleks. Albinex has been working with the Daleks all along, which is why he was at the battle in the first place; with the Destructor Codes he will be able to start a war on Earth and allow the Daleks to invade two centuries ahead of schedule. Roz and Chris lead a team to Albinex’s yacht, while the Doctor, Isaac, Benny and Jason go to the missile base to stop Albinex. Albinex sends the ghost to stop them, but she has stretched herself too thinly and dissipates before the Doctor can save her. Albinex has killed the guards and is just about to launch the first missile when the Doctor and Isaac arrive, and Graeme the spatula distracts Albinex just long enough for the Doctor to stun him with a touch. It is too late to stop the launch, but the Doctor redirects the missile and it flies off harmlessly into space -- destroying the Dalek satellite which had been sent to monitor the progress of Albinex’s plan.
The Doctor contacts C19 and UNIT, who spin a cover story about the launch and agree to work with Isaac from now on. Mrs Randrianasolo departs, knowing that she will never be able to trust Isaac again, but many others remain on his team to continue the good work of the railroad -- including Joel, who was possibly transported back in time by a glitch in Albinex’s time engines. The Doctor recovers the TARDIS and sends both the missile and Albinex’s yacht into the sun, intending to take Albinex back to Navarino for psychiatric treatment; he will also take home whichever of the stranded aliens will accept a lift from him. Finally reunited and reconciled with her father, Benny returns to the 26th century with Jason, to start the rest of her life.