After his regeneration at the end of Logopolis, the Doctor is still weak, and his companions, Adric, Nyssa, and Tegan take him to his TARDIS. Adric, spotting a Corinthian column nearby, investigates only to realize too late that it is the Master's TARDIS, and is abducted. In the Doctor's TARDIS, the Doctor is delirious but asks to be taken to the "Zero Room" that contains Time Lord healing technology to allow him to recover.
Left to wait for the Doctor to recover, Tegan and Nyssa discover a terminal on the TARDIS that describes how to use the machine. They attempt to pilot the TARDIS but find they are traveling rapidly to a preset time and destination, "Event One", the Big Bang, a trap set by the Master. The women manage to bring the Doctor out of the Zero Room to the console room in time for him to jettison a quarter of the TARDIS' mass to propel them back to conventional time. They soon discover that the Zero Room was part of the jettisoned mass, and with the help of Nyssa and Tegan, build a temporary coffin from the TARDIS panels to attempt to recover. Using the same terminal, Tegan discovers information on the Dwellings of Simplicity on Castrovalva, an ideal place for the Doctor to recover, and directs the TARDIS there.
Nyssa and Tegan have difficulties in transporting the Doctor on Castrovalva, and become separated from him; the Doctor is captured by warriors protecting the Dwellings, while the women are forced to climb a rocky cliff to reach its entrance. The Doctor is cared for by Shardovan, a librarian, and the elderly Portreeve, before Nyssa and Tegan arrive. After a night's sleep, they discover strange aspects of the Dwellings; they cannot easily find an exit and appear to circle back to the same plaza, and that a tapestry in the Doctor's rooms change and reflect events of the outside world. The Doctor comes to realize they have been trapped in a recursive occlusion, and that the Dwellings are fake. Portreeve reveals himself as the Master, and shows them Adric, caught in a web-like structure. The Master has been able to use Adric's mathematical genius along with the block-transfer computations of the Logopolians to create the Dwellings as well as alter the TARDIS, creating the terminal on the console that led them here. Realising the true nature of Castrovalva's reality, Shardovan swings from a chandelier into the web and destroys it, freeing Adric and causing the reality of the Dwellings to fall apart. Seeing all is lost, the Master flees to his TARDIS, which was disguised as a fireplace. The Doctor and his companions flee from the city. The Master appears to be trapped and is unable to escape as the city collapses in on itself. As the time travellers return to the TARDIS, the Doctor indicates that he has fully recovered from his regeneration ordeal.