Warned of upcoming danger by the TARDIS' Cloister Bell, the Doctor decides to stay out of trouble, and instead spends time fixing his broken chameleon circuit by extracting the measurements of a true police box on Earth in order to give to the mathematicians of the planet Logopolis. He is unaware that the Master is aware of his plan, and materializes his own TARDIS in a recursive loop with the Doctor's. The Doctor and Adric work out the recursion, and attempt to flush the Master out by materializing the TARDIS in the River Thames, but instead land on a boat on the river with no sign of the Master's TARDIS. Outside, the Doctor sees a glowing white figure, the Watcher, who directs him to hurry to Logopolis. In flight, they discover they have picked up a passenger, Tegan Jovanka, an airline stewardess that wandered in the TARDIS to call for help to fix her aunt's flat tyre; the Doctor informs her the Master has killed her aunt with his Tissue Compression Eliminator.
On Logopolis, where the mathematicians perform their block-transfer calculations by chant-like verbal communication, the Doctor gives the lead mathematician, the Monitor, the new dimensions for the TARDIS. Discovering the calculation result to be flawed, the Doctor discovers the Master's handiwork in the death of several mathematicians. Returning to the Monitor, the Doctor finds the Master, who through mind-control of Nyssa (who believes him to be the Keeper of Traken) is holding the Monitor hostage. The Master demands to know the secret behind Logopolis' science and the purpose of an exact replica of a space telescope from the Pharos Project on Earth, using a device to temporarily silence the mathematicians. The Monitor is horrified to find that even when the Master disables the device, the mathematicians have gone silent, and they discover that Logopolis is being overrun by entropy and turning to dust. The Monitor reveals that their calculations were used to model Charged Vacuum Emboitments (CVEs) as a means of excising off excess entropy from this universe into others as to stave off the imminent heat death of the universe; without the calculations, the CVEs have disappeared. Before the Monitor turns to dust, he reveals that a program contained in the bubble memory of their computers may be able to restore one CVE. The Doctor and Master agree to work together to return to Earth and use the Pharos Project there. Meanwhile, Nyssa, after having been freed of the Master's control and Adric are abducted aboard the Doctor's TARDIS by the Watcher and taken far outside of the galaxy, where they observe a large section of the universe including the Traken Union consumed by entropy. They manage to reset the controls for Earth, locking in on the Master's TARDIS when it arrives.
While the Doctor's companions set to distract the guards, the Doctor and Master make their way to the control room and successfully execute the CVE program. However, the Master reveals he plans to hold the universe hostage, threatening to stop the program. The Doctor is forced to climb onto the telescope's dish and disconnect a power cable while the Master attempts to turn it to knock the Doctor off. While the Doctor is successful in ending the Master's threat, he hangs precariously from the dish and sees images of his various enemies before he falls to the ground. The Doctor's companions rush to the spot where he has fallen. Dying, the Doctor experiences visions of the companions that have accompanied his current form and observes, "It's the end... but the moment has been prepared for." They turn to see the Watcher approach, and as he does so he merges with the Doctor. Nyssa realises that the Watcher was the future Doctor all the time. As the companions look on, the Fourth Doctor regenerates into a new, younger body—the Fifth Doctor.