The Doctor learns from the psychic alien Ood that his archnemesis the Master (John Simm) will shortly return, heralding "the end of Time itself". On present day Earth, a cult loyal to the Master attempt to resurrect him; the Master's ex-wife, Lucy Saxon (Alexandra Moen) sabotages the ceremony however, and the Master is brought back suffering from constant hunger, also having gained superhuman strength and speed along with energy projection from his constantly expending energy. The Doctor attempts to trace the Master, on Christmas Eve, and encounters his friend Wilfred Mott (Bernard Cribbins), to whom the Doctor explains a prophecy that he is to die soon. The Doctor tracks the Master to wastelands outside of London, where the Master subdues him and forces him to listen to the sound of drums in his head. The Doctor discovers that the sound is not a symptom of the Master's insanity but something implanted in him from outside. But before the Doctor can learn more, the Master is abducted by troops and placed in the custody of billionaire Joshua Naismith (David Harewood).
Wilfred is repeatedly warned by an apparitional woman in white (Claire Bloom) to arm himself to protect the Doctor before joining him in the TARDIS. They travel to the Naismith estate where they discover Naismith is in possession of an alien "Immortality Gate" and has enlisted the Master to fix its programming. Aliens of the Vincocci species reveal themselves and attempt to explain that the device is a simple medical device from their homeworld, but are unsuccessful. The Master ultimately uses the device to replace all of humankind with his DNA, creating a 'Master Race' where everyone looks like the Master; exceptions to this are Wilf, who is shielded from its effects, and Wilf's granddaughter Donna (Catherine Tate), a former companion of the Doctor who acquired Time Lord biological traits in an earlier adventure. The Master and his doppelgangers taunt the Doctor, who can only look on in horror.
Far across the Universe, the episode's narrator (Timothy Dalton) remarks that the Master's removal of humanity is only the beginning of far greater events; the narrator is revealed to be the Lord President of the Time Lordsthe Doctor and Master's species who addresses a vast chamber full of other Time Lords, and announces that it is "the day the Time Lords returned. For Gallifrey! For victory! For the end of Time itself!"
The Doctor and Wilfred are rescued from the Master by the Vinvocci, taking refuge on their orbiting ship. Meanwhile, the Time Lord President receives a prophecy about the future after the Time War, and so schemes to use the Master to one day escape. They are able to put a signal in the young Master's head as a small child, creating the drum beat he has heard all his life. When the Master clones himself billions of times, the Time Lord President also sends a "whitepoint star" from their home planet Gallifrey to the Master in the present day to strengthen the connection between present-day Earth and Gallifrey, which presently is "timelocked" in the middle of a Time War, shortly before its destruction, a fate which it is otherwise unable to escape. Gallifrey materialises above Earth, and all the other horrors of the Time War are likely to follow. The Doctor, armed with Wilfred's gun, breaks into the room from above, but vacillates over whether to kill the Master or the President in order to sever the link; he eventually spots the whitepoint star and shoots it instead. As he does this, he catches sight of and recognises the woman in white from earlier, and is saddened. As the Time Lords are drawn back into the Time Lock, the Presidentwhom the Doctor names, at the last minute, as Rassilonattempts to kill the Doctor, but the Master intervenes, sacrificing himself in an act of revenge against Rassilon. In a flash of light, the Time Lords, the Master, and Gallifrey all disappear. Taking a moment to realise his victory, the Doctor hears four knocks, the sound which he has been told will precede his death. He finds Wilfred, having returned to help the Doctor, still trapped in the Gate's isolation chamber that will be flooded with radiation due to the Master's modifications; only the self-sacrifice of another will free him. The Doctor releases Wilfred, collapsing in agony as he receives a massive dose of radiation. Although he survives initially as his body absorbs the radiation, the healing of the Doctor's wounds shows his regeneration process has begun, which means he will soon change appearance and personality.
After taking Wilfred home, the Doctor somberly visits past companions and acquaintances. Companions Martha Jones (Freema Agyeman) and Mickey Smith (Noel Clarke) have married and are working as freelance alien hunters; the Doctor saves them from a Sontaran sniper. The Doctor rescues Luke Smith (Tommy Knight) from an oncoming car, and silently acknowledges Luke's mother, former companion Sarah Jane Smith (Elisabeth Sladen). At an extraterrestrial bar, the Doctor passes a note to a despondent Captain Jack Harkness (John Barrowman), encouraging him to start a conversation with Midshipman Alonso Frame (Russel Tovey), seated next to him. The Doctor appears at a book-signing by Verity Newman (Jessica Hynes), the great-granddaughter of Joan Redfern (Hynes), from the episodes "Human Nature" and "The Family of Blood", and asks whether Joan was happy. Newman's book, A Journal of Impossible Things, is based on Joan's diaries, concerning her earlier love affair with the Doctor. He then attends Donna's wedding, and gives her a winning lottery ticket bought with money borrowed from Donna's deceased father to assure their financial future. Finally, the Doctor visits Rose Tyler (Billie Piper), on New Year's Day 2005, the year when she meets him as the Ninth Doctor. He tells her she will have "a great year". As the Doctor struggles towards the TARDIS, Ood Sigma (Paul Kasey) appears before the Doctor, and tells him the universe will sing him to sleep and that "this song is ending, but the story never ends"; a diegetic symphony then accompanies the Doctor as he regenerates. The Doctor says "I don't want to go", and the violent energy his body releases as he transforms shatters the TARDIS windows and sets the console room ablaze. With his regeneration complete, the Eleventh Doctor (Matt Smith) inspects his new body before realizing that the TARDIS is hurtling back to Earth.