A narrator describes two royal sisters who ruled over the magical land of Equestria. The elder sister used her powers to raise the sun, while the younger sister brought out the moon at night. The younger sister became resentful because the ponies of Equestria relished daytime but slept at night. One night, she refused to lower the moon. She transformed into Nightmare Moon, a "wicked mare of darkness," and vowed to shroud Equestria in eternal night. Her sister used the Elements of Harmony to banish her to the moon, and took on responsibility for both sun and moon. The narrator's voice changes to that of Twilight Sparkle, who reads that harmony has been maintained in Equestria ever since.
Twilight walks by Lemon Hearts, Twinkleshine, and Minuette, who invite her to Moondancer's party. Twilight says she has to study and runs off. She enters a library atop an ivory tower and instructs Spike to find a book called "Predictions and Prophecies". Twilight realizes that Nightmare Moon will return on the day of the Summer Sun Celebration, which is the day after tomorrow. She sends a letter to Princess Celestia to alert her. Celestia's reply to Twilight says that she trusts Twilight completely, but she has to stop reading "those dusty old books".
Spike continues to read Celestia's letter on the way to Ponyville. Celestia tells Twilight that there's more to life than studying, and tasks her with supervising the preparations for the Summer Sun Celebration in Ponyville. The letter ends with one other task for her: make some friends.
Once they reach Ponyville, Twilight and Spike visit Sweet Apple Acres to check on the catering for the Summer Sun Celebration first. Applejack cordially greets Twilight and members of her family offer her food samples. Twilight wants to leave, but she grudgingly accepts the family's invitation to stay for brunch.
After brunch, Twilight looks at the cloudy sky and remarks that Rainbow Dash isn't doing a very good job of clearing the sky for the festival. Rainbow Dash says she will do it after she practices some flying moves to show the Wonderbolts at the festival. She demonstrates her speed and agility by clearing the sky in "ten seconds flat." She says she can't wait to hang out with Twilight some more, and flies away.
Twilight and Spike visit Rarity, who is decorating the town hall. Spike is instantly smitten with Rarity. She is shocked by Twilight's messy mane and gives her a makeover in Carousel Boutique. She is impressed when Twilight mentions that she is from Canterlot. Eager to get away from the fashionista, Twilight and Spike sneak out of the boutique.
The last item to check for the Summer Sun Celebration is music. Twilight greets Fluttershy and compliments her bird choir, but Fluttershy is too shy to introduce herself. However, she gets excited when she sees Spike because she has never seen a baby dragon before. She follows Twilight and Spike to Golden Oak Library, where they will be staying. Inside the library, Twilight and Spike are greeted with a surprise party. Pinkie Pie starts talking to Twilight about how she was surprised to see a new pony in town and decided to throw her a party. Twilight accidentally drinks hot sauce and runs out of the room with her mane on fire. In her bedroom on the second floor, Twilight complains that making friends has left her no time to read about the Elements of Harmony. She guesses that Princess Celestia sent her to Ponyville because she thinks the Mare in the Moon is just an "old pony's tale."
In the town hall, Mayor Mare announces the beginning of the Summer Sun Celebration, but Princess Celestia is absent. Nightmare Moon steps out of a glowing blue fog and addresses the cowering ponies:
"Am I not royal enough for you? Don't you know who I am?"
Rainbow Dash tries to fly towards Nightmare Moon, but Applejack pulls her back. Pinkie tries to guess Nightmare Moon's name, but Applejack shoves a cupcake in her mouth to stop her from doing so. Twilight declares that the dark alicorn is the Mare in the Moon— Nightmare Moon. Impressed, Nightmare Moon asks Twilight if she also knows why she's here, but Twilight is too terrified to answer. Nightmare Moon proclaims that the night will last forever, and cackles as a thunderstorm builds up around her, with Twilight looking on in disbelief and fear.
In Golden Oak Library, Twilight Sparkle and her friends find a book about the Elements of Harmony. They learn that the elements of kindness, laughter, generosity, honesty, and loyalty are known, but the sixth is a mystery. The book also says that the Elements are stored in the royal sisters' ancient castle in the Everfree Forest. The ponies decide to look for the Elements and are unaware that Nightmare Moon has been listening to their conversation the whole time.
The ponies enter the Everfree Forest. When they are walking on a mountainside, a cloud of purple smoke triggers a landslide. Fluttershy and Rainbow Dash catch Rarity and Pinkie Pie, but Twilight slides to the edge of a steep cliff. Applejack assures Twilight that she will be safe if she lets go of the cliff. Twilight lets go, and Rainbow Dash and Fluttershy catch her. Then an angry manticore confronts the ponies. When the other ponies try to forcefully subdue it, Fluttershy tells them to stop. She kindly approaches the manticore. It shows her a thorn stuck in its paw. She removes the thorn and the grateful manticore licks her mane. The thorn dissolves into purple smoke, which zooms away. Next the ponies come across a river blocked by a sea serpent. The sea serpent is upset that a "tacky little cloud of purple smoke" whisked by and tore off half his mustache. Rarity generously donates her own tail to repair the sea serpent's mustache. The sea serpent, extremely pleased and grateful, helps the ponies cross the river. Now the castle ruins are in sight, but the ponies cannot cross a gorge because the bridge is broken. When Rainbow Dash flies to the other side to fix the bridge, three Pegasi appear and invite her to be captain of the Shadowbolts, their group of elite fliers. When Rainbow Dash learns that she must desert her friends to join the Shadowbolts, she turns down the Shadowbolts and ties the bridge so her friends can cross. The Shadowbolts turn into purple smoke, which slithers away.
The ponies enter the castle ruins and find five stone orbs, which Twilight believes are the first five Elements of Harmony. Nightmare Moon creates a purple whirlwind that teleports Twilight and the orbs to another tower. Nightmare Moon and Twilight face off, but Nightmare Moon shatters the orbs. The friends run into the hall and comfort Twilight. Twilight realizes that the spirits of the Elements are present, and explains how her friends represent the elements of honesty, kindness, laughter, generosity, and loyalty. The fragments of the orbs begin to circle the friends. A stone orb magically appears over Twilight, and she declares:
"You see, Nightmare Moon, when those Elements are ignited by the... the spark, that resides in the heart of us all, it creates the sixth element: the element of... magic!"
The orb fragments form golden jeweled necklaces on the five friends' necks, and Twilight's orb becomes a crown. The Elements glow and the ponies are lifted into the air. A rainbow-colored double helix envelopes Nightmare Moon. The room is flooded with light. When the light fades, the friends discover that the gems on their necklaces resemble their cutie marks, and Rarity's tail has magically grown back. Princess Celestia appears with the sunrise and explains that Twilight had the magic to defeat Nightmare Moon as long as she let true friendship into her heart. Nightmare Moon returns to her original form, Princess Luna. The friends learn that Luna is Celestia's younger sister, and the sisters reconcile and reunite after 1000 years of separation.
Back in Ponyville, Pinkie throws a party to celebrate the royal sisters' reunion. When Twilight tells Celestia that she doesn't want to leave her new friends, Celestia gives her a new mission: to continue studying the magic of friendship in Ponyville and report back her findings. Twilight promises to study harder than ever, much to the delight of her new friends and the citizens of Ponyville.
