The fifth and final installment of the Underland Chronicles opens with twelve-year-old Gregor lying in a prophecy room in Regalia, a human city in the Underland, the subterranean world beneath New York City. He has just returned from the Firelands, a volcanic region where he witnessed a giant white rat called the Bane order the mass slaughter of mice. Now he reads the prophecy everyone has been hiding from him. Called "The Prophecy of Time," it describes a war, a code that must be broken, and one unbearable line: "WHEN THE WARRIOR HAS BEEN KILLED." Gregor is the warrior. He knows he cannot abandon the Underland, not with Ares, his bonded bat partner, and Luxa, the twelve-year-old queen of Regalia, depending on him. Luxa's grandfather Vikus, head of the Regalian council, reassures him that prophecies can be misinterpreted.
After treatment for ash exposure, Gregor learns that Solovet, Luxa's grandmother, has been reinstated as head of the army despite awaiting trial for weaponizing plague germs. His mother lies gravely ill with pneumonia in the hospital, and when Gregor appeals for her transfer home, he discovers Solovet has blocked all requests to keep him in the Underland. Solovet also assigns him armed guards to prevent escape.
Gregor outmaneuvers the guards during a game of hide-and-seek in the nursery, slipping through a secret passage. Ares catches him, and they fly to the Firelands, where Luxa, her cousin Howard, and Ripred, a giant rat allied with the humans, are fighting to evacuate surviving mice. Gregor's rager ability, a combat state that makes him a devastating fighter, activates fully. He fights alongside Ripred at the tunnel mouth as mice stream through. When the retreat is complete, Luxa orders flaming arrows fired into an oil-filled tunnel, incinerating the pursuing rat army. Then she coughs blood and collapses.
Gregor holds Luxa upright during the flight to Regalia, talking to keep her conscious. While waiting for news, he is ambushed by his guards and locked in a dark cell beneath the palace. In the darkness, he discovers he can echolocate: The months of failed training with Ripred have paid off. Nerissa, Luxa's frail, visionary cousin, arrives and tells him Luxa is alive. Brought before Solovet, Gregor faces a return to the dungeon until Ripred reveals Gregor's feelings for Luxa, detected by scent. Mareth, a soldier and Gregor's friend, confirms with a photograph Gregor carries. Solovet, confident he will not flee, releases him.
Gregor is taken to the code room, where representatives of each species work to crack the Code of Claw, an unknown cipher the rats use. His three-year-old sister Boots has been assigned as the human code-breaker based on the prophecy's mention of a "princess," but she has contributed nothing. Then his eight-year-old sister Lizzie arrives after their grandmother is hospitalized and their father relapses into illness. Ripred calms her panic attack with math problems and poses a logic puzzle she solves instantly, recognizing Lizzie as the true code-breaker the prophecy requires.
While crossing the farmlands, Gregor is attacked by enormous moles called diggers. Vikus explains that these creatures originally owned Regalia's land, but Sandwich, the city's founder, poisoned their water supply, a genocide that earned humans the name "killers." Gregor's moral certainty crumbles. He also overhears Ripred tell Lizzie that he once had a mate and pups who died in a flood, and that he returned from despair because he refused to accept their deaths meant nothing.
Lizzie triggers a breakthrough when she explains anagrams, noting that "Gregor" and "Gorger" contain the same letters. The code team realizes this is the key: Letters shared by both names remain unchanged while all others shift by one position. Lizzie tests the cipher and deciphers a message instantly. Ripred orders absolute secrecy.
Decoded messages reveal a planned rat attack through the river and the death of Twitchtip, a scent-seer rat who was Gregor's ally, after imprisonment and likely torture. Gregor breaks down weeping for the first time in the war. The rats invade through the river but are repelled. However, Solovet is killed in an ambush the code team intercepted but could not act on without revealing their advantage. Vikus has a stroke upon learning of her death.
Before the final battle, Ripred privately tells Gregor he does not believe in Sandwich's prophecies, arguing they are vague enough to fit many situations and that people fulfill them through their own decisions. He tells Gregor flatly that he is not going to die.
The surprise attack on the Plain of Tartarus, where the Bane's forces have regrouped, involves humans, mice, cockroaches, spiders, and rebel rats. Mid-battle, Gregor spots Lizzie and Boots trapped in a cave; Ripred races to defend them. Gregor and Ares lure the Bane into a remote cavern. Ares maneuvers Gregor close enough to drive his sword through the Bane's heart, but the Bane catches Ares and sinks his teeth into the bat's neck. The Bane's dying swipe tears open Gregor's chest. Ares is dead. Gregor drags himself to his bond and believes he is dying.
Gregor wakes two weeks later. His father has come to bring the family home. His hand is still locked around Ares's claw; Luxa gently cleans and wraps it after he lets go. Ripred is believed dead, thrown into a pit of flesh-eating mites while defending Gregor's sisters.
At the surrender ceremony, a battered figure claws out of a tunnel: Ripred, half his fur eaten away, one leg useless, but alive. Luxa proposes banishing the rats; Ripred refuses. Both turn to Gregor. He erupts, naming the dead and demanding to know how they can start another war. He snaps Sandwich's sword over his knee and declares: "The warrior's dead. I killed him." Nerissa cries out that this fulfills the prophecy: The warrior has been killed, not literally but symbolically.
Luxa rejects treaties as unreliable and instead proposes a bond between humans and rats, a sacred vow to defend each other to the death. She raises her hand; Ripred presses his paw against it. They recite the oath together. Lizzie suggests peace negotiations be conducted by seven delegates, one per species, each chosen by the other species.
Gregor says goodbye. Aurora and Nike, two of Regalia's bats, fly the family to the stairway beneath Central Park. Gregor tells Luxa he loves her; she says the same. They kiss, and his father slides the stone into place.
Back in New York, violent nightmares fill Gregor's sleep. He visits Mrs. Cormaci, a family friend, who promises support. He rides the subway to the Cloisters museum to see the stone knight whose image sustained him through the war. Standing before the tomb, he realizes the knight can no longer help him: He spent months learning how to die, and now he must learn how to live. That evening, Boots sits on his lap in a playground and hands him a small plastic bat. "Ares," she says. Gregor notices that Boots, who has always called him "Gre-go," can finally say his full name. This small sign of growth offers a quiet closing note of hope.