Twilight's Kingdom

Part one

Princess Twilight Sparkle and her friends travel to the Crystal Empire, where Twilight is to help greet delegates from another nation. She finds this duty unfulfilling, and laments this to Celestia, Luna, and Cadance, unsure what her role in Equestria is. The other three assure her that her responsibilities will become clear in time.
Celestia has a vision revealing that a centaur named Tirek has escaped from Tartarus and is now draining ponies of their magic. Gathering the other princesses, Celestia explains how they had stopped Tirek before and that they must stop him now before he becomes too powerful. Twilight is eager to help, but Celestia instead puts Discord in charge due to his ability to sense magical imbalances caused by Tirek's activity. Twilight returns home to Ponyville, disappointed at being unable to help, and heads for the ancient castle in the Everfree Forest to catch up on studying. Discord interrupts them, teases them about his mission, and reminds them of the locked chest at the base of the Tree of Harmony (from "Princess Twilight Sparkle"). Twilight suspects there may be something to help against Tirek inside, and she and her friends search the books in the castle. Twilight realizes Discord mentioned their shared journal, and finds stories written by the other five where they were challenged in regards to their core Element of Harmony, and were able to help another, receiving an item in return. They gather these items, which transform into five of the six keys needed to open the box, but Twilight realizes that she has not yet faced a challenge similar to theirs and thus cannot provide the last key.
Discord encounters Tirek, but he teases him with having freedom over friendship, so Discord decides to join forces with Tirek and reverts back to his old ways. Twilight is summoned back to Canterlot, where Celestia reveals Discord's treachery and that Tirek now has his sights set on taking the princesses' magic for himself.

Part two

Celestia reveals that the best plan to prevent Tirek from getting the alicorn magic is to hide it away within Twilight since her recent ascension to Princess is still unknown to Tirek. They transfer their powers to Twilight, who has difficulty in controlling the power and avoids her best friends on returning to Ponyville while she practices control.
Tirek confronts the princesses and finds their magic gone. Despite this setback, he mocks that their plan is unable to change anything and banishes the three to Tartarus. He then expresses his gratitude for Discord's assistance by giving him a medallion as a sign of loyalty. As they discuss this, Tirek learns of Twilight's existence and sets off to Ponyville. With Discord's assistance, they trap Twilight's friends and Tirek steals their power. He then turns on Discord and takes his magic as well, having only used Discord as a pawn to become powerful as he tells him he is no longer useful to him. Tirek finds Twilight and when she tries to run away, he destroys the Golden Oak Library in Ponyville. Enraged, Twilight attacks Tirek and after a battle between the two superpowered beings, they realize they are evenly matched and Tirek offers to release Twilight's best friends in exchange for her magic. Twilight realizes this is the same type of situation that her best friends had previously experienced and agrees to the deal on the condition that her friends and Discord are freed. Tirek takes the alicorn magic and begins to go on a rampage.
Remorsefully, Discord apologizes to Twilight's friends for betraying them and gives Twilight the medallion Tirek had given him as a sign of his true friendship. Twilight recognizes this as the sixth key, and they quickly race to the box. With all six keys present, the box opens and powers the Tree of Harmony, causing Twilight and her best friends to be infused with a rainbow-like power. Together, they face Tirek, repulse his attacks and revert the magic drain. Tirek is weakened to his frail form and returned to Tartarus while Twilight and her best friends return the magic to all the other ponies in Equestria and free the princesses. The box is then sent by the Tree of Harmony into the ground at the edge of Ponyville, and grows into a tree-like castle. Celestia informs Twilight that since she is now the Princess of Friendship, her responsibility is to continue helping spread friendship across Equestria with the help of her best friends, including Discord.

Production

Tirek is a reinvention of the main antagonist of Rescue at Midnight Castle, which was produced by Sunbow Productions and Marvel Productions. Meghan McCarthy noted that they "cannot show Twilight punch Tirek in the face".
Twilight's castle was designed by Phil Caesar in conjunction with art director Ridd Sorensen and BG painter Geoff Manson. When asked about the name of Twilight's new castle, Friendship is Magic season 5 supervising director Jim Miller replied, "You'll have to wait 'til Season 5 to find out!". In late November 2015, Miller confirmed that the castle's name is simply "Castle of Friendship".

Broadcast and reception

Both parts of "Twilight's Kingdom" aired back-to-back on the Hub Network as an hour-long event on May 10, 2014. Part 1 of the finale was viewed by 677,000 viewers and was watched by approximately 0.3 percent of households in the United States, according to the Nielsen household ratings. Part 2 of the finale was viewed by 788,000 viewers and, also according to the Nielsen household ratings, was watched by approximately 0.4 percent of American households. 
The two episodes received critical acclaim. An Entertainment Weekly writer graded them an A−, describing the two as carrying "a Frozen-y empowering theme (and a sly Godfather reference)". James Zahn from The Rock Father considered the finale "an exciting pair of episodes," adding that "fans of My Little Pony will be discussing these episodes for some time to come." On Tirek's character, Zahn wrote, "The Emperor to Discord's Darth Vader, Tirek is exciting, bringing with him a ... dash of that classic 80s evil." Daniel Alvarez on Unleash the Fanboy gave the finale a 10 out of 10 and called it a masterpiece, praising the general pacing and writing of the episodes. He also considered Tirek a "brilliant antagonist, by far, the best villain the show has seen yet" and favorably compared the battle between Twilight and Tirek to Dragon Ball Z.

Home media release

The two-part finale is part of The Keys of Friendship DVD, alongside "Rarity Takes Manehattan" (Season 4, Episode 8), "Pinkie Apple Pie" (Season 4, Episode 9) and "It Ain't Easy Being Breezies" (Season 4, Episode 16), which was released on July 29, 2014. The episode was also part of the Season 4 DVD, which was released on December 2, 2014.