Princess Celestia learns of the reappearance of the Crystal Empire. Previously the home of the Crystal Ponies over one thousand years in the past, the empire had been taken over by the tyrant unicorn King Sombra who enslaved the ponies and threatened to use their power to take over Equestria; Celestia and her sister Luna had sealed King Sombra away in ice, but Sombra cursed the empire to vanish as a last effect. Now that it has reappeared, Celestia and Luna both fear that Sombra will reappear as well and re-conquer the empire, becoming too powerful for even them to defeat again. Celestia assigns her student Twilight Sparkle with a test of her ability, and hers alone, to help her brother Prince Shining Armor and his wife Princess Cadance to protect the empire.
Twilight travels with her mare friends, as well as Spike, to the arctic where the empire is located. The shadowy form of Sombra appears as they near the city, but Shining Armor arrives and protects them as they race for cover within a magic shield around the city. Though they are safe, Shining Armor is afflicted with a dark magic which disables his own powers. The mares and Spike meet Princess Cadance at the castle, where she has been enchanting the shield day and night without sleep and little food. Twilight and her friends spread out to ask the citizens about how to protect the empire without Cadance's magic, but find that the Crystal ponies are afflicted with a spell that has erased their memories of anything before King Sombra's reign, making them miserable.
Twilight finds a book about the Crystal Empire's past, learning of a Crystal Fair used to raise the spirits of the Crystal Ponies. She and her friends go about to recreate the fair; Twilight assumes that one aspect, a Crystal Heart, is a ceremonial piece and constructs a crude version of it from crystal. As Cadance's magic starts to falter, the fair starts, and the Crystal Ponies soon cheer up and slowly remember their past. Rainbow Dash overhears one discuss part of the ceremony of the fair where they would channel their elated feelings into the Crystal Heart to protect the Empire; Rainbow races back to warn Twilight they need to find the real Crystal Heart, and Twilight discovers that the page about the Heart's powers has been purposely torn out from the book. Just then, Cadance's magic completely shuts down as she collapses in Shining Armor's arms, gasping for air, allowing King Sombra to surround the Empire.
With Shining Armor's support, Cadance re-engages the shield just in time, though a slice from King Sombra's horn lands within the shield and slowly starts to taint the land, turning it back into its dark appearance during his reign. Twilight instructs her friends to keep the fair going while hiding the fake Crystal Heart, while she goes and looks for the real one by herself, assured that this is the test Celestia has given her. Spike insists on coming along, promising not to help in any way.
Twilight surmises that King Sombra had hidden the Heart in the castle, as the Crystal Ponies had feared his reign and would never had entered it. Twilight's unique abilities with magic allow her to pass through several traps laid by Sombra until she and Spike reach the top of the castle. They find the Crystal Heart waiting for them, just as Cadance exhausts her magic completely. As Sombra invades the Empire, Twilight goes for the Heart, but becomes trapped by a wall of dark crystals that prevent her escape when Sombra is alerted to her attempt, while the Heart falls at Spike's feet.
Twilight frets how to escape the trap in time before realizing that the only solution is to have Spike deliver the Heart to the ponies below, even though she believes this will cause her to fail her test to Celestia. Spike races ahead of King Sombra's attacks, but falls off with the Heart. Shining Armor throws Cadance at Spike and the Heart; she catches both in time before King Sombra can get there, and glides down to the base of the castle, the Crystal Heart restoring both her strength and magic. Quickly placing the Heart in its proper place, Cadance addresses the Crystal Ponies as their princess and instructs them to power the Heart. The positive feelings from the ponies cause the Heart to be recharged, and destroy King Sombra and his dark magic for good. With the Heart restored, the Crystal ponies regain their crystalline appearance, and the effect extends to Princess Cadance, Shining Armor, and Twilight and her friends, while they remain in the city.
Twilight and her friends say their goodbyes to Princess Cadance and Shining Armor and return to Canterlot. Twilight finds that while Spike has been considered the hero of the adventure, even being rewarded with a stained glass window of his accomplishment, Princess Celestia asserts that Twilight has passed her test, having demonstrated self-sacrifice by putting the interests of others ahead of her own. Twilight rejoins her friends as they celebrate her success while Princesses Celestia and Luna look on, with Luna holding a mysterious book (later revealed to be Star Swirl the Bearded's notebook in "Magical Mystery Cure").