K9, retroactively "K9 Mark I" (Leeson), initially appeared in The Invisible Enemy (1977) as the creation of Professor Marius (Frederick Jaeger) in the year 5000. K9 subsequently travelled with the Fourth Doctor (Tom Baker) and Leela (Louise Jameson) as a companion of the Doctor in his adventures in time and space until The Invasion of Time (1978). In this serial, K9 decides to remain on the Doctor's home planet of Gallifrey with Leela. Immediately afterwards, Doctor Who would introduce a second incarnation of K9, played by the same prop; the last scene of The Invasion of Time shows the Doctor unpacking a box labeled "K9 Mk II".
Either Inspector Thorne or Lomax found out about K9's regeneration unit and decided to acquire it. Thorne joined forces with Freddie Maxwell, owner of Crashclub involving old robots being made to fight. K9 went undercover as a gladiator and made friends with the robot clowns Chuckles and Boris. He was called to fight the Pain-Maker, who was laced with the explosive solarmite. When he was set to self-destruct, K9 detected this and fled the explosion. (TV: Robot Gladiators) To regain his memory and find out his connection to the STM, K9's archive was scrambled. Directives from the STM almost caused him to self-destruct and lose all his memory. However, with Gryffen and Starkey's help he overrode the directives. (TV: Mind Snap) He helped Gryffen find the STM's temporal stabiliser from the fallen angel crash site in Canada, where it was revealed to be Korven technology. (TV: Angel of the North) He stopped haywire CCPCs when The Last Precinct's plan backfired. (TV: The Last Precinct)
A short story, "Moving On", in Virgin Publishing's Decalog 3: Consequences anthology and the Big Finish Productions-produced Sarah Jane Smith audio play Mirror, Signal, Manoeuvre (both written by Peter Anghelides) indicate that K9 Mark III broke down and Sarah was unable to repair it as the replacement circuits would not be invented for several centuries.
Within the series' narrative, K9 is a robot dog acquired by Doctor Who's title character in the 1977 serial The Invisible Enemy. The first two incarnations of the character travelled alongside the Fourth Doctor (portrayed by Tom Baker) until 1981. In these stories, K9 proved useful for the powerful laser weapon concealed in his nose, his encyclopaedic knowledge and his vast computer intelligence. By 1981, each of the two models of K9 which travelled alongside the Doctor had been left with one of the Doctor's female companions. The character subsequently transitioned into spin-off territory. Producers hoped K9's popularity with children would launch the series K9 and Company, led by actress Elisabeth Sladen in the role of companion Sarah Jane Smith alongside a new K9. In 2006, K9 reappeared in the revived series of Doctor Who. Although the character's appearances in the 2007 spin-off The Sarah Jane Adventures were hampered by the concurrent development of the K9 spin-off, the character began to appear full-time in both K9 and The Sarah Jane Adventures, depicting adventures of the original K9 Mark I and of Mark IV, respectively.