The book begins shortly after the ending of The Colour of Magic , with wizard Rincewind, Twoflower and the Luggage falling from the Discworld. They are saved when the Octavo, the most powerful book of magic on the Discworld, readjusts reality to prevent the loss of one of its eight spells, which has resided in Rincewind's head since his expulsion from Unseen University: Rincewind, Twoflower and the Luggage end up in the Forest of Skund. Meanwhile, the wizards of Ankh-Morpork use the Rite of Ashk-Ente to summon Death in order to find an explanation for the Octavo's actions. Death warns them that the Discworld will soon be destroyed by a huge red star unless the eight spells of the Octavo are read.
Several orders of wizards travel to the forest of Skund to try and capture Rincewind, who is currently staying with Twoflower and the Luggage in a gingerbread house in the forest. In the subsequent chaos, Rincewind and Twoflower escape on an old witch's broom, while the Archchancellor of Unseen University is killed when his attempt to obtain the spell accidently summons the Luggage on top of him, crushing him to death. His apprentice, Ymper Trymon, uses the opportunity to advance his own power, intending to obtain the eight spells for his own good.
Rincewind and Twoflower run into a group of druids who have assembled a "computer" formed from large standing stones, and learn of the approaching red star. As Twoflower attempts to stop the druids from sacrificing a young woman named Bethan, Cohen the Barbarian, an octogenarian parody of Conan, attacks the druids. Twoflower is poisoned in the battle, forcing Rincewind to travel to Death's Domain to rescue him. The pair narrowly avoid being killed by Ysabell, Death's adopted daughter, and as they escape Death's Domain, Rincewind learns from the Octavo itself that it had arranged for its eighth spell to escape into his head, in order to ensure the spells would not be used before the right time.
Rincewind and Twoflower travel with Cohen and Bethan to a nearby town, where the toothless Conan leaves to have some dentures made for him, having learned of them from Twoflower. While he is gone, Rincewind, Twoflower and Bethan are attacked by a mob of people who believe the star is coming to destroy the Discworld in response to the presence of magic. The trio escape into one of many shops that sell strange and sinister goods and inexplicably vanish the next time a customer tries to find them. The existence of these shops is explained as being a curse by a sorcerer upon the shopkeeper for not having something in stock. They are able to return to Ankh-Morpork via the shop.
As the star comes nearer and the magic on the Discworld becomes weaker, Trymon tries to put the seven spells still in the Octavo into his mind, in an attempt to save the world and gain ultimate power. However, the spells prove too strong for him and his mind becomes a door into the "Dungeon Dimensions", home to a manner of eldrich creatures. Rincewind and Twoflower manage to kill the now-mutated Trymon, and Rincewind reads all eight of the Octavo's spells aloud. This causes eight moons of the red star to crack open and reveal eight tiny world-turtles that follow their parent A'Tuin on a course away from the star. The Octavo then falls and is eaten by the Luggage.
Twoflower and Rincewind part company as Twoflower decides to return home, leaving the Luggage with Rincewind as a parting gift. Cohen and Bethan also leave to get married. Rincewind decides to re-enroll in the university, believing that with the spell out of his head, he will finally be able to learn magic.