Hartnell's performance in This Sporting Life was noted by Verity Lambert, the producer who was setting up a new science-fiction television series for the BBC entitled Doctor Who; mainly on the strength of that performance, Lambert offered him the title role. Although Hartnell was initially uncertain about accepting a part in what was pitched to him as a children's series, in part due to his success in films, Lambert and director Waris Hussein convinced him to take the part, and it became the character for which he gained the highest profile and is now most remembered. Hartnell later revealed that he took the role because it led him away from the gruff, military parts in which he had become typecast, and, having two grandchildren of his own, he came to relish particularly the attention and affection that playing the character brought him from children. His first episode of Doctor Who was aired on 23 November 1963.
Doctor Who earned Hartnell a regular salary of £315 an episode by 1966 (in the era of 48 weeks per year production on the series), equivalent to £5,764 in 2018. By comparison, in 1966 his co-stars Anneke Wills and Michael Craze were earning £68 and £52 per episode at the same time, respectively. Throughout his tenure as the Doctor, William Hartnell wore a wig when playing the part, as the character had long hair.
According to some of his colleagues on Doctor Who, he could be a difficult person to work with. Others, though, such as the actors William Russell and Peter Purves, and the producer Verity Lambert, spoke glowingly of him after more than 40 years. Carole Ann Ford, who played the Doctor's granddaughter Susan, has said that she and Hartnell "got on terribly well", saying "It upsets me when I hear people saying he was difficult to work with, he was very sweet". Hartnell also adored Verity Lambert and had great respect for Waris Hussein. Hartnell also admired African American singer Paul Robeson. In his Desert Island Discs interview, Hartnell stated that Paul Robeson was his hero and described him as having a voice like crushed velvet. Hartnell described Robeson in his own words, "this man's voice is so rich", saying "to me, he is completely in harmony with the whole of nature and it sounds just liquid poetry".
Hartnell's deteriorating health (he suffered from arteriosclerosis) began to affect his ability to learn his lines, and he had a poor relationship with a new production team on the series following the departure of Verity Lambert. He left Doctor Who in 1966. When he departed the producer of the show came up with the idea that, since the Doctor is an alien, he can transform himself physically, thereby renewing himself. William Hartnell himself suggested the new Doctor, stating that "There's only one man in England who can take over, and that's Patrick Troughton." In the fourth episode of the serial The Tenth Planet the First Doctor regenerates into Troughton's Second Doctor.
Many of Hartnell's episodes are missing from the BBC archives as a result of the BBC's purge of old shows during the early 1970s.
Hartnell reprised the role of the Doctor in Doctor Who during the tenth anniversary story The Three Doctors (1972–73). When Hartnell's wife Heather found out about his planned involvement she informed the crew of the show that his failing memory and weakening health prevented him from starring in the special. An agreement was made between the crew and Heather that Hartnell would sit down during the shoot and read his lines from cue cards. His appearance in this story was his final piece of work as an actor.