As the Keeper of the Matrix arrives in the Trial room, the Inquisitor asks the Doctor whether he has any further evidence for his defence. He says that he does not, and accuses the Valeyard's evidence of being a farrago of lies, worthy of Baron Munchausen. He maintains that the Matrix has been tampered with. The Keeper denies that it is possible, as no one may enter the Matrix without the Key of Rassilon. The Inquisitor accepts the Valeyard's argument that the Doctor's allegation is unsubstantiated. Yet the Doctor insists the evidence has been deliberately tampered with by someone who wants him dead, such as the Valeyard. With the evidence complete, the Doctor learns that the Master has gained access to his Tardis.
Two capsules are summoned to the Gallifreyan space station containing Sabalom Glitz and Melanie Bush. The Inquisitor says the only way for the Doctor to prove his allegation of evidence tampering would be to produce witnesses. Just as he is saying that would be impossible to do so, as any witnesses would be scattered through time and space, Mel and Glitz arrive in the Court Room. The Doctor and the Inquisitor asks who has sent them, and on the Matrix screen, the Master appears to announce that it is he who has done so. He is within the Matrix proving the Doctor's allegation to be true — he has obtained a copy of the Key of Rassilon. He states that justice must be done, not because he does not want to see the Doctor dead, but because he cannot countenance a rival. He stares meaningfully at the Valeyard.
The Valeyard tries to discredit anything Glitz will say by calling him a convicted criminal, but even he cannot impugn Mel's character. The Master nevertheless asks that Glitz be allowed to speak. The Doctor begins to question Glitz, who admits to being the Master's business partner. The Doctor asks about the information Glitz was trying to obtain on Ravolox, which Glitz reveals were technological secrets stolen by the Sleepers from the Matrix. The Keeper is shocked at the allegation, and Glitz says that Sleepers had found a way to break into the Matrix and take the secrets back to Andromeda. Eventually the Time Lords discovered what was happening and traced the Sleepers to their secret base on Earth. Planning to wipe out all the Sleepers, the High Council planned to use the Magnetron — a formidable device which dragged the Earth across space thereby causing a fireball nearly annihilating all life on the planet. The robot recovery mission from Andromeda then sped past Earth, and the Gallifreyan secrets were safe, However, the Sleepers managed to set up an underground survival chamber.
The Doctor gives an impassioned speech, denouncing the Time Lords as decadent and corrupt. Comparing them to the Daleks, Cybermen and Sontarans, he says those races are still in the nursery of evil. The Inquisitor tries to stop the Doctor's outburst, but in his fury he says that the outrage would have remained secret for centuries. The Master says that the High Council took advantage of the Doctor's blundering into the situation on Ravolox. They made an arrangement with the Valeyard — who he has always known as the Doctor — to arrange the evidence against the Sixth Doctor. In return he would receive the remainder of the Doctor's regenerations. The Master reveals the true identity of the Valeyard — an amalgamation of the Doctor's dark side somewhere between his twelfth and final regenerations. The Sixth Doctor demands the trial be brought to an immediate halt — otherwise the same person would be both prosecutor and defendant. The Inquisitor dismisses this as the inquiry's purpose is simply to determine the truth of the defendant's actions, but at this moment, the Valeyard flees the trial room.
The Doctor, Glitz, the Inquisitor and the Keeper follow him out but the Valeyard is nowhere to be seen. The Keeper suggests that the Valeyard may have had a copy of the key to the "Seventh Door" of the Matrix. Unlocking the door, the Doctor and Glitz enter into the fictional reality that is the Matrix, whilst the Inquisitor and Mel return to the Trial room.
The Doctor finds himself in a darkened city street. He hears the maniacal laughter of the Valeyard but he is nowhere to be seen. He hears children singing and people laughing, but again he does not see a living soul. As he examines a barrel, a hand emerges and grabs his throat choking him. At this moment, Glitz arrives and runs to his rescue. The Doctor is unable to tell if the experience was real or imaginary. He says that the only logic at work in the Matrix is that there is no logic at all. Glitz presents him with a note from the Master, telling him where the Valeyard has his base — the Fantasy Factory, proprietor J. J. Chambers. They look up and see a building with a huge illuminated sign "The Fantasy Factory". A harpoon is hurled from the building and hits Glitz in the chest.
The Master tells the Inquisitor that most of the evidence that had been presented was in fact true. However, Peri survived the events on Thoros Beta and became King Yrcanos's queen.
Glitz survives as he was wearing a life preserver. The Doctor says the Valeyard is playing games, trying to humiliate the Doctor. Glitz wants to leave the Doctor to his fate, but the Doctor tells him as the only witness to events, the Valeyard would be forced to track him down and kill him. He grudgingly agrees to help the Doctor.
The Inquisitor asks the Master if he has any proof of his allegation that the Doctor and Valeyard are in fact the same person, to which he replies he should examine the High Council. It was they who set up the travesty of the Trial to cover up their own involvement. She asks him his concern in the matter — to which he says that the Doctor is well matched against himself in his battle. Mel calls him utterly evil, which he takes as a compliment. He thinks the Valeyard will win, but hopes that the battle might result in their mutual destruction. The Master chuckles with malevolent glee at the thought of destroying the Doctor and destabilising the High Council of Time Lords, a great result for a renegade like him.
In the Fantasy Factory, the Doctor is confronted by a quill writing clerk who proceeds to studiously ignore him. When the Doctor rings his bell, the clerk asks if he has an appointment to see Mr. Chambers. The Doctor says he will be expected, and the clerk asks for his and Glitz's names. The clerk informs them that there will be many forms to be completed before they can move onto the next stage of processing. To the clerk's dismay, the Doctor and Glitz burst into the next room without an appointment. In the next identical room, they see an identical clerk, but this one is expecting them. He informs them that the very junior Mr Popplewick is not permitted to expect anyone. The Doctor tells this clerk that the proprietor is expecting them, to which he sharply replies that the junior Mr Popplewick is not permitted to expect anyone. The Doctor asks the clerk if there is anyway to expedite the procedures, but the clerk sees no need to speed up what he considers a perfect system. The Doctor tells him that the proprietor wants him dead, and finally defeated, the clerk admits that the Doctor has found the one weakness in the procedure. The clerk gives the Doctor a form, asking him to sign away his remaining lives to Mr Chambers should he meet an unforeseen accident within the factory. Knowing that the Valeyard can kill at any time anyway, the Doctor signs it.
Directing them to the waiting room, the Doctor finds himself alone in a deserted wasteland. Again he hears the Valeyard's maniacal laughter, and out of the gravel hands reach up and grab the Doctor by the ankles. He refuses that what is happening is real, but more and more hands reach up and grab him, and the Valeyard's voice tells him this is not an illusion, not this time. The Doctor is slowly dragged beneath the ground.
Glitz arrives to rescue the Doctor and sees just his ankles sticking out of the ground. He grabs a shoe but it comes away. He hears the Doctor's voice coming from below, and the Doctor rises from the ground. The whole scenario had been an illusion. The Valeyard appears and taunts the Doctor. The Doctor asks him why he wants him dead, and why he is going to such extraordinary lengths to kill him. The Valeyard tells him that by destroying the Doctor, and with unlimited access to the Matrix, nothing will be outside his reach. The Valeyard disappears, and an oncoming cloud of nerve gas forces the Doctor and Glitz to run.
In the trial room, the Inquisitor and Mel look on helplessly. Mel tries to grab the key from the Keeper so that she might enter the Matrix herself, but he trips her over in the attempt.
In the Matrix, the Doctor and Glitz find a cottage in the wasteland, and stumbling inside, it dematerialises. It is the Master's TARDIS. The Master tells the Doctor he wants him to annihilate the Valeyard. The Valeyard, with all of the Doctor's abilities but none of his moral qualms, would make him a formidable force of evil, greater than the Master. Also, if the Valeyard killed the Doctor, it would rob the Master of that personal pleasure. The Doctor is mentally assaulted by the Master, leaving him in a catatonic state. The TARDIS materialises outside the fantasy factory. Using the zombified Doctor as bait, the Master and Glitz hide in the shadows. The Valeyard emerges on a balcony, with the Doctor in plain sight. The Master shoots at him with his Tissue Compression Eliminator, but its beams simply deflect off the Valeyard. The Valeyard hurls exploding quills at them and re-enters the factory building. The Master flees leaving Glitz and the Doctor behind.
Mel's voice is heard calling out to the Doctor, rousing him from the catatonic state. Following her voice he seemingly leaves the Matrix and re-enters the trial room. The Inquisitor tells him that he owes the Court an apology. She tells them that charge of genocide is supported by his own evidence. Replaying the scenes of the Vervoids' destruction, Mel tells the Court that the scenes are exactly as she witnessed them. The inquisitor tells the Doctor that he has been found guilty of genocide, and that he is sentenced to death. The Doctor says that he accepts the verdict…
However, in the real Trial room, the last scene is revealed to be taking place within the fictional realms of the Matrix. Mel disturbed by what she has seen and rails against the non-interference of the Time Lords present. Grabbing the Key from the Keeper she arrives for real in the Matrix. She sees the Doctor being led to his execution on a horse-drawn carriage. She tells him that the trial was an illusion, but he had already realised that — he wanted to force a confrontation with the Valeyard.
The Master tries to hypnotise Glitz so that he will lead the Doctor to the Valeyard. The hypnotism fails, but the Master uses something guaranteed to persuade the rogue — a huge chest full of treasure. He enters in the Fantasy Factory and finds the secrets he thought had been destroyed on Ravolox. Mr Popplewick catches him looting, and tells him that the Ravolox secrets were a copy, and what Glitz is holding is the master tape. Also in the factory, the Doctor finds a list of Time Lords — all the members of the supreme court of appeal. The Doctor realises the list is written in his own handwriting. Glitz manages to "persuade" Popplewick to take him to Chambers, and finding the Doctor, takes him along.
In the court yard, Popplewick hands the secrets over to Glitz. Glitz asks him not to tell the Doctor and Mel he betrayed them. As Glitz walks away, Popplewick tries to shoot him, but his gun is not loaded. The Master arrives, and he and Glitz return to the TARDIS.
In another building, the Doctor is admiring a steam-driven machine when Popplewick arrives and goes to search for Chambers. When he is unable to do so, the Doctor and Mel grab a hold of him, and the Doctor peels away Popplewick's mask to reveal the Valeyard. The Doctor realises that Popplewick was the Valeyard because of his own penchant for Grand Guignol. Mel opens a door marked danger, behind which is a device which she recognises as a megabyte modem. The Doctor corrects her, it is a maser. The Valeyard is using it as a particle disseminator, with which he plans to murder all the members of the court through the matrix screen in the trial room.
In the trial room, the Keeper of the Matrix brings the Inquisitor serious news, the High Council has been deposed and there is insurrection on Gallifrey. The Master appears on the matrix screen to give an edict. He offers to impose order with his control over the matrix, but anyone who disobeys him will be executed. In his TARDIS, he loads the matrix secrets master tape into the time machine's systems, but the tape has been booby-trapped with a Limbo Atrophier, which causes both he and Glitz to be pushed back against the TARDIS walls, unable to move.
Mel runs into the trial room to warn the Time Lords of the impending danger. The Inquisitor says that the screen cannot be switched off without the Keeper of the Matrix present, so Mel tells them to run for their lives. The Doctor sabotages the maser, but balls of energy shoot from the matrix screen where the Time Lords are cowering. The Doctor believes he has set the machine to self-destruct but the Valeyard tells him that it will in fact feedback into the Matrix. As the balls of energy swirl around the fantasy factory, the Valeyard collapses over the maser.
The Doctor flees and makes it back to the court room. There the Inquisitor tells him that all the charges have been dropped, and to the Doctor's relief, that Peri survived and is living with Yrcanos. She asks if the Doctor will stand for Lord President, but he suggests that the Inquisitor should stand instead. He asks that when the Master and Glitz are recovered, that the Time Lords show some leniency towards Glitz. He and Mel depart in the TARDIS with Mel threatening the Doctor with a regime of strict exercise and carrot juice.
As the Inquisitor departs the trial room, she gives instructions to the Keeper of the Matrix, but as he looks up, he gives a quiet chuckle, and is revealed to be the Valeyard…
Doctor Colin Baker (Sixth Doctor)
Companion Bonnie Langford (Melanie Bush)
Anthony Ainley — The Master
Lynda Bellingham — The Inquisitor
Michael Jayston — The Valeyard
Tony Selby — Sabalom Glitz
Geoffrey Hughes — Popplewick
James Bree — Keeper of the Matrix
Writer Robert Holmes (episode 13)
Pip and Jane Baker (episode 14)
Director Chris Clough
Script editor Eric Saward (episode 13)/John Nathan-Turner, uncredited (episode 14)
Producer John Nathan-Turner
Executive producer(s) None
Production code 7C-2
Series Season 23
Length 2 episodes, 25 minutes and 30 minutes
Originally broadcast November 29–December 6, 1986