As the Doctor broods over the lives he failed to save on Gallifrey, the TARDIS materializes on board the Queen Mary, an ocean liner, on a night in October of 1963. Exploring, the Doctor meets a steward named Simpkins, who assumes that the Doctor is the magician from the ship’s cabaret. A woman begins screaming, and the Doctor and Simpkins investigate to find a terrified passenger, Miss Lamb, who claims to have seen a ghost. The Doctor believes that she was having a nightmare, but Simpkins claims that he’s heard many stories which suggest that the ship is indeed haunted. Simpkins takes a gloomy relish in pointing out the ship’s watertight bulkheads, with edges so sharp they could slice a man in two, and advises the Doctor to avoid Cabin 672 at all costs. Something terrible once happened there, and the cabin has remained empty ever since.
The Doctor spends the night watching the sea, and as dawn breaks, he joins the other passengers in the forward bar, seeking company to lift him out of his bleak mood. Miss Lamb is sitting with a group of friends and colleagues, and after inadvertently embarrassing her by asking if she’s recovered from her nightmare, the Doctor engages in a pleasant conversation about the class system with her employer, a self-made man named Bryce. Afterwards, he leafs through a newspaper, and is amused by an article about quantum physicist Peter Osbourne, who is visiting America to inquire about funding for his research into methods of time-travel. Simpkins and his friend Jarvis then join him, but the Doctor, still trying to cheer himself up, brusquely dismisses their tales of ghosts and takes his leave -- only to be confronted by a transparent spectre in the corridor outside the lounge.
The Doctor tries to deny the reality of his vision, but over the course of the day more and more ghosts appear to him. Some are ill-defined wraiths, others are transparent human shapes, and others take the form of screaming skulls. When the Doctor tries to communicate with them he is overpowered by a sense of misery and pain, and eventually, a coherent message directs him to Cabin 672. He tries to investigate, but the psychic terror, anger and despair emanating from the cabin is too powerful even for him, and he flees back to the TARDIS. However, some force is holding the TARDIS on the ship, refusing to let it dematerialize.
Trying to avoid returning to Cabin 672, the Doctor runs into Miss Lamb, who appears to have fully recovered from her night terrors. They fall into a pleasant conversation about the Romantic poets and Miss Lamb’s duties as Bryce’s personal assistant, but as they approach the ship’s swimming pool the Doctor has an overpowering vision of Miss Lamb’s death by drowning. When he tries to warn her, Miss Lamb admits that she is also psychically sensitive, and that although she’s tried to deny it, she can sense the spirits on the ship. She takes the Doctor’s advice and returns to her cabin -- but, later that night, accidentally drowns in her bathtub. Bitter and infuriated by his failure, the Doctor tries once again to leave, but cannot, and this time accepts that he has no choice but to confront the evil in cabin 672.
Instead of entering cabin 672 directly, the Doctor tries entering the cabin next to it, but even in cabin 673 the shock of the psychic screams is enough to knock him out for several hours. When he recovers, he forces himself to enter cabin 672, where he finds a man with the demeanour of a stereotypical mad scientist. This is Peter Osbourne, the quantum physicist, and he’s already invented a prototype time visualiser. Osbourne bribed the stewards to let him work in this cabin, where he would not be disturbed, and has set up an experimental machine with which he hopes to look through Time and see events throughout history. However, it has had an unexpected side effect. The Doctor is horrified to realize that the machine’s bell jar has trapped portions of life essence from everyone who has ever been or ever will be on the ship. The “ghosts” are fragments of people’s spirits, caught at the times of their greatest despair and fear, when their emotions are at their strongest. Cabin 672 is the psychic centre of the ship, not because of any terrible event in the past, but because of what Osbourne has done on this journey.
The Doctor tries to convince Osbourne that he’s done a terrible thing and is tormenting the spirits he’s trapped, but Osbourne proves to be utterly amoral; despite the horrifying results, he is proud of himself for exploring new territories of science and inventing something that has never been conceived of before. The Doctor sees a ghostly image of Simpkins cut in half, caught in eternal torment, but Osbourne remains convinced that he has made a great achievement and refuses to intervene to save Simpkins’ life. The Doctor gives up trying to make him see reason, and before Osbourne can object, he smashes the bell jar, releasing the trapped spirits in a blast of psychic energy which knocks him out for several hours.
When the Doctor awakens, Osbourne and the spirits have gone. Initially satisfied, the Doctor heads back to the TARDIS, but on the way back he encounters a crowd of seamen by one of the emergency bulkheads. Simpkins, finally overcome by his own despair, has locked himself behind the bulkhead, and though the other crewmen try to talk him down, he uses another bulkhead to slice himself in half. Subdued by his inability to save Simpkins despite the warning of his fate, the Doctor returns to the TARDIS, only to find the ghosts waiting to see him off. He has freed them from Osbourne’s machine, but the gestalt will always be bound to the fabric of the ship, and now Osbourne is trapped with the spirits as well.