Sontaran invasion of Gallifrey

The Sontaran invasion of Gallifrey was an attempt by the Sontaran Empire to take control of Time itself.

Prelude
When the Third Doctor encountered the Sontaran, Linx on Earth in the 13th century, he informed Linx that he was a Time Lord from Gallifrey. The Sontaran revealed that he knew of the Doctor's world and people. Linx considered the Time Lords to be "a race of great technical achievement, but lacking the morale to withstand a determined assault" — which made the Doctor invite him to "put that theory to the test". (TV: The Time Warrior)

After assassinated the Time Lord President, the Fourth Doctor put himself forward as a candidate for election to gain legal protection. 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, 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 Eye of Harmony. 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
In the years that followed, details of the invasion were taught at the Time Lord Academy. (AUDIO: Insurgency)

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.