"Valeyard" is a title meaning "Learned Court Prosecutor". when the High Council of the Time Lords asked The Valeyard to make an impartial enquery in to the Doctor's activities. After Valeyard successfully argued that the Doctor was guilty of interferance, a Time Lord high crime, the enquery quickly became a trial. The Doctor would have faced the death penalty, if The Valeyard's true identity had not been discovered.
The Valeyard, it turned out was created by the corrupt High Council of the Time Lords and was actually an amalgamation of the darker side of Doctor's nature, somewhere between his twelfth and final incarnation. Fearing that the Doctor would expose the truth about Ravolox and their involvment, the High Council offered the Doctor's remaining regenerations to the Valeyard if he would destroy his earlier incarnation. The Valeyard proceeded by introducing false evidence from the Matrix concerning the Doctor's activity on Ravolox and Thoros-Beta, including a false account of Peri's death. He later accused the Doctor of genocide for having destroyed the Vervoids. Thanks to the Master's assistance, the Doctor eventually exposed the Valeyard, who then fled into the Matrix.
In the Matrix, the Valeyard plotted to murder the Time Lords attending the trial with a particle disseminator. The Doctor eventually thwarted the Valeyard's plans, but the evil Time Lord escaped again, taking over the body of the Keeper of the Matrix.