The Doctor's trial (The Mysterious Planet)

Originally begun as an impartial inquiry into the behaviour of the Doctor, the Sixth Doctor's trial was brought about due to the significant loss of human life in the prosecution's first evidence. The prosecutor was the Valeyard and Darkel acted as inquisitor, presiding over the evidence. The Doctor refused the right of a court defender. The Valeyard's award for winning was the Doctor's remaining regenerations.

The Doctor was taken out of time at a critical moment by the Time Lords and placed in Space Station Zenobia when he arrived in court. The initial charge was that "he, on diverse occasions [had] been guilty of behaviour unbecoming of a Time Lord". The Doctor denied the charges. Before the first evidence was presented, discussion of the Second Doctor's trial took place where it was highlighted that the Valeyard deemed the punishment to be too lenient.

The Valeyard's first evidence was the Doctor's involvement in the affairs of Ravolox. At some points, the sequence had been censored by the High Council because the information contained within were deemed not suitable for the public. Although the Valeyard offered Darkel the opportunity of consuming it privately she denied as it was unfair to the defendant. After the sequence on Ravalox had finished the Valeyard escalated the inquiry to a trial punishable by death because the Doctor's meddling had caused the loss of human life, or at least more than if he had not interfered. (TV: The Mysterious Planet)

The Valeyard's next evidence was the adventure the Doctor had been involved in concurrently to his removal from time on Thoros Beta. During its course, the Doctor accused the evidence from the Matrix to be slightly altered to portray him as harsher. Also notable was the death of the Doctor's companion, Peri Brown – arguably as a result of the Doctor's actions – as well as the use of Yrcanos as an assassin by locking him in a time bubble so he could completely destroy Crozier's experiments. (TV: Mindwarp)

The Doctor's first evidence was taken from his future; his defence being the fact he would improve. Over the course of the sequence the Doctor again accused the Matrix of presenting false evidence – namely, a sabotage he supposedly committed, and encouragement into danger directed at his companion, Mel. At the conclusion of the adventure, the Doctor completely destroyed the Vervoid race to prevent them wreaking more havoc and death if even a single leaf landed on fertile soil. Latching onto this, the Valeyard invoked article 7 which prohibited genocide, claiming it allowed no exceptions. (TV: Terror of the Vervoids)

To satisfy the Doctor's accusations of tampering within the Matrix, Darkel summoned the Keeper, who reiterated that it was impossible to gain access to the Matrix without a key, something the Doctor highlighted could be copied. Then, appeared on the Matrix screen with just that; he had been watching events unfold, but now intervened to defeat the Valeyard. He sent two witnesses of the Doctor's version of events: Sabalom Glitz and Mel. The Doctor's questioning of Glitz revealed that the High Council moved the Earth light years from its position to stop the secrets of the Matrix from being uncovered, causing the fireball that wiped out almost all life. The Master also added that the Valeyard was an amalgamation of all that was evil in the Doctor and that he had made a deal with the High Council to frame the Doctor to cover up their actions. With these revelations, the Valeyard fled the courtroom and entered the Matrix as the Doctor and Glitz followed.

After a confrontation with the Valeyard leading to his plan of assassinating the jurors of the Doctor's trial through the Matrix screen being defeated by the Doctor, the latter returned to the courtroom. Darkel informed him that all charges against him had been dropped and suggested that he run for President once law and order was restored. He declined, and he and Mel left in the TARDIS to continue their adventures. Darkel told the Keeper to repair the Matrix with anything he needed, but the Keeper had been replaced by the Valeyard. (TV: The Ultimate Foe)

Alternate timelines
A parallel universe existed where the Valeyard convicted the Doctor and gained his remaining regenerations. (AUDIO: He Jests at Scars...)

In an alternate timeline, the Doctor of that world was also placed on trial, but the outcome led to his re-integration into Time Lord society as Lord Burner. (AUDIO: Disassembled)

Behind the scenes
In the original idea for The Ultimate Foe the Doctor and the Valeyard would have tumbled through the Matrix, fighting to the death, with the battle's outcome left unknown, but with the assumption that they would be locked in eternal combat if no one intervened. This was rejected by producer John Nathan-Turner, who thought it would have encouraged Michael Grade to cancel the show.