After the wizard Rincewind has fallen from the edge of the Discworld, the Octavo magic book saves his life and he lands back onto the world. Meanwhile, the wizards of Ankh-Morpork discover from Death that the Discworld will soon be destroyed by a huge red star unless the eight spells of the Octavo are read: the most powerful spells in existence, one of which hides in Rincewind's head. Consequently, several orders of wizards try to capture Rincewind, led by Trymon, a former classmate of Rincewind's, who wishes to obtain the power of the spells for himself.
After Rincewind, who has met again with Twoflower, escapes them, it becomes apparent that Great A'Tuin, the giant turtle that carries the Discworld, has set a new course that leads it directly into a red star with eight moons. Rincewind and Twoflower are accompanied by Cohen the Barbarian, a toothless, aging hero, and Bethan, a sacrificial virgin saved by Cohen, with assistance from Rincewind and Twoflower.
Rincewind becomes one of the very few people ever to enter Death's Domain whilst still alive, where he finds Twoflower playing a card game with the Four Horsemen of the Apocalypse. He is nearly killed when he meets Death's adopted daughter Ysabell, but is saved by the quick-acting Luggage. The group also encounter people who, anticipating the apocalypse, are heading for the mountains (not for protection, but because they will have a better view). As well as this, they happen upon the kind of shop where strange and sinister goods are on sale 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.
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", whence strange, horrible creatures try to escape into reality. The seven leading wizards are meanwhile turned to stone. After winning a fight against them, Rincewind is able to read all eight spells aloud; whereupon the eight moons of the red star 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 Twoflower's Luggage.
The book ends with Twoflower and Rincewind parting company, as Twoflower decides to return home, leaving The Luggage with Rincewind as a parting gift.