Sontaran invasion of Gallifrey

The Sontaran invasion of Gallifrey, also referred to as the Vardan/Sontaran invasion or Sontaran/Vardan invasion, (PROSE: The Eight Doctors) was an attempt by the Sontaran Empire to take control of Time itself.

Prelude
After assassinated the Time Lord President, the Fourth Doctor put himself forward as a candidate for election to gain legal protection as he was believed to be the assassin, and the Time Lords were threatening him with vaporisation. The only other candidate was Goth, who was in league with the Master and who was subsequently killed. The Doctor left Gallifrey without assuming the office of President. (TV: The Deadly Assassin)

The invasion
The Vardans, who wished to invade Gallifrey, later contacted the Doctor. As part of an elaborate plan where he would pretend to help them so he could deal with the Vardans as they were a threat, he agreed to help them. He arrived on Gallifrey and claimed the title of President, then deactivated the transduction barrier. The Capitol was placed under Vardan control. The Doctor had duped them, however, and ultimately defeated them, sealing Varda in a time loop.

Indeed, the Vardans had been doubly duped. Their invasion was no more than a front for the Sontarans, who marched into the Panopticon and took control. The Sontarans, led by Stor, easily overcame Time Lord resistance, helped by the sycophantic Castellan, Kelner.

The Doctor retreated into his TARDIS along with Leela, Andred, Borusa, Rodan and K9 Mark I. The Doctor had consulted the Matrix and had learnt how to construct the fabled Demat Gun. He placed Rodan under hypnosis and instructed her to build the weapon.

The Sontarans pursued the Doctor through the TARDIS but were defeated. Stor went to the Panopticon in a last-ditch suicide attempt to destroy the galaxy, including the Time Lords. The Doctor fired the Demat Gun, obliterating Stor. The Demat Gun disappeared and the Doctor lost all memory of the invasion. (TV: The Invasion of Time) However, he did somehow later recall wishing he'd thrown the President to the Sontarans while he had the chance. (TV: The Ribos Operation)

Aftermath
Romana I had witnessed the panic of Gallifrey being invaded, later noting the same panic when a mountain in Shangdong almost blew up. (PROSE: The Shadow of Weng-Chiang)

In the years that followed, details of the invasion were taught at the Time Lord Academy. (AUDIO: Insurgency) The invasion was also the event that revealed the existance of the Matrix to the universe at large. As such, the Cloister Wars began. (PROSE: Dalek: The Astounding Untold History of the Greatest Enemies of the Universe)

Noticing that Thessalia had regenerated, Larissa wondered if it had been during "the goblin infestation". (PROSE: Newtons Sleep)

Behind the scenes

 * Commander Stor and his battle on Gallifrey is mentioned by Commander Strax in the fourth-wall-breaking cinema intro for The Day of the Doctor. He is disappointed to learn that the anniversary feature is about the Doctor as opposed to a Sontaran historical drama featuring heroic accounts of their various military campaigns which he was anticipating with his clone batch.