Nightmare Moon

"Remember this day, little ponies, for it was your last. From this moment forth, ''the night will last forever!"

- Nightmare Moon

Nightmare Moon is one of the villains of My Little Pony: Friendship is Magic, and the main antagonist of the two-part pilot episode "Friendship is Magic" also known as "Mare in the Moon". Before that, she was known as Princess Luna, and is the younger sister of Princess Celestia.

History
Long ago, Luna and Celestia were both the rulers of Equestria, a land inhabited by ponies. Every morning, Celestia would raise the sun, and every evening, Luna would raise the moon. Together, they kept the balance perfectly. One day, however, Luna grew jealous: the ponies would be awake to enjoy the day and love, admire, and appreciate Celestia's work, but would always sleep through her far more beautiful night. In anger, Luna refused to lower the moon, thus bringing eternal night. Celestia tried to reason with Luna, but the bitterness in her heart had transformed her into a corrupted form of herself: Nightmare Moon. To protect Equestria, Celestia used the Elements of Harmony to magically seal her sister inside the moon, creating the phenomenon known as "the Mare in the Moon" (a unicorn's face imprinted upon the surface of the moon). It is said that in a thousand years, on the longest day of that year, Nightmare Moon will make her return.

Nightmare Moon's return and redemption
Upon reading an ancient legend, Twilight Sparkle realized Nightmare Moon is about to return, however her mentor, Princess Celestia, encouraged her to make friends instead of worrying about the supposed "old pony's tale". Unfortunately, Twilight turned out to be right and Nightmare Moon was released during the Summer Sun Celebration, replacing Celestia who was supposed to attend it. Twilight and her soon-to-be friends chased Nightmare Moon into the forbidden Everfree Forest.

After conquering many obstacles left by Nightmare Moon in their path, they finally found the twisted mare herself along with the ancient Elements of Harmony, now reduced to inert stones. As Nightmare Moon whisked the Elements away, Twilight followed her into the portal and confronted her alone. She tried to use the Elements of Harmony like Celestia did, but for that she had to find the "spark" that would make a sixth Element appear. However, no matter how hard she tried, she couldn't make the spark, and Nightmare Moon destroyed the Elements.

Fortunately, when Twilight heard her new pony friends calling for her, she felt a different spark in her heart; making her realize that the real Elements are not just some stones: they exist in the hearts of her friends. That spark triggered the final element: Magic (also known, of course, as Friendship), and reanimated the shattered Elements, converting them into jewels for the six friends to bear. Using the Elements of Harmony, Twilight activated a spell that struck Nightmare Moon, exercising the darkness from her and transforming her back into Princess Luna.

Celestia arrived in the ruins where the battle took place, admitting that she knew of Nightmare Moon's return, but knew the only way to defeat her was for Twilight to understand the importance of friendship. Celestia walked over to a cowering Luna, who apologized in tears for her actions, and was granted forgiveness. Later at the celebration (held by Pinkie Pie), even the other ponies forgave Luna, gifting her with a flower necklace.

Nightmare Night
In the season 2 episode "Luna Eclipsed", Princess Luna, now uncorrupted (And with a new look. Lauren Faust, the show's creator, stated that this was because when Nightmare Moon was defeated, Luna was reborn with very low magic levels, and she transformed after getting her good powers back), returns to Ponyville during the holiday Nightmare Night, a holiday dedicated to Nightmare Moon depicting her as a scary bogeyman. Luna, with Twilight's help, tries to change her image from that of the terrifying Nightmare Moon, to a favorable one as Princess. Unfortunately, the nature of the holiday, combined with Luna's outdated mannerisms and flair for the dramatic, make her subjects more scared of her than ever. Her first attempts end disastrously, prompting her to decree Nightmare Night canceled, but Twilight persuades her to give Ponyville another chance. When Luna discovers that the residents actually enjoy being scared as part of the night's festivities, she uses the Nightmare Moon persona to help them have fun and thus gains their trust and friendship.

Season 4
In Season 4, a preview has been shown of Luna becoming Nightmare Moon. It is implied that this is a flashback sequence that Twilight is experiencing from Celestia's point of view, given Luna's line about "precious light".

Other appearances
Luna has a few cameos in the season 2 finale A Canterlot Wedding, flying in to guard Canterlot at nighttime, ironically not participating in the fight against the changelings for reasons unknown. After Chrysalis was defeated, Luna appeared next to Celestia and the Mane 6, asking if she missed anything.

She also appears in the season premier The Crystal Empire.

At the beginning of Seasons 2 and 3, it's revealed that Luna, alongside Celestia, turned Discord to stone with the Elements of Harmony and imprisoned King Sombra in ice while turning him to shadow, about a thousand years ago sometime before her transformation into Nightmare Moon.

Nightmare Moon in comics
In Issue 6 (Part 2 of the second arc), the nightmare forces turn Rarity into a new Nightmare Moon called Nightmare Rarity, possessed by their darkness. It is also said that the nightmare forces told Nightmare Moon/Luna what to do to make ponies fear her, that she promised them a kingdom of their own, and Luna thought they would die with the evil of Nightmare Moon gone, but they instead returned to the moon for one more chance in the cycle of the new moon.

In Issue 7, Nightmare Rarity imprisons the ponies in her dungeon once the Nightmare Forces defeat them, and resists Spike's attempts to get through to her. She tries to trick him with an illusion, but he realizes her deception. She has Shadowfright and his sidekick capture him and says the nightmare has only begun.

In Issue 8, the ponies escape the dungeon and decorrupt Shadowfright's sidekick, Jerome, with the power of friendship. Luna does the same to Shadowfright and his army, turning them back into the denizens of the moon. The ponies then use this power of friendship on Nightmare Rarity to weaken her, and with this, them thinking of memories of Rarity, and Spike's love for her along with his restored Fire Ruby, the Nightmare Energy and spirit of Nightmare Moon are destroyed, releasing Rarity from their control.

Nightmare Rarity speaks as if she were the original Nightmare Moon, and speaks of Rarity as a separate character, hinting that Nightmare Moon is the manifestation of Luna's bitterness magnified by or merging with the Nightmare Forces, returned through the cycle of the new moon to possess Rarity.

Luna appears in the comics as well, though not as Nightmare Moon, and with her mane and tail the way they were after she was restored.

Note: It is up for the fans to decide whether the comics are canon.

Theories
There are several theories about Nightmare Moon and Luna which say they're not the same entity. This was confirmed by Lauren Faust herself. Nightmare Moon could be in fact an enbodiment of dark magic possessing Luna and keeping her prisoner under her evil influence till she was finally released by the Elements of Harmony.

As King Sombra made the Crystal Empire disappear for a thousand years, it was speculated that he had something to do with Luna's transformation into Nightmare Moon. He could have magnified her existing jealousy and bitterness into a dark transformation, or, in accordance with the above theory, a manifestation that possessed her. This theory may have been proven wrong as it was revealed that Celestia and Luna defeated Sombra in the past and imprisoned him, though that does leave the possibility that Sombra only started a more gradual transformation from Luna into Nightmare Moon.

It has been said that there was an outside force behind Luna's transformation into Nightmare Moon, who also might have had a hand in Discord's escape. In the comics it is implied that this force was the Nightmare Forces.

Trivia

 * Nightmare Moon's backstory and her goal of bringing eternal darkness, as well as sometimes taking the form of dark smoke, gives her an undeniable resemblance to Makuta Teridax from the Bionicle series. Her being imprisoned on the moon and escaping her prison after a thousand years echoes the stories of Queen Nehelenia and the Shadow Queen, respectively. The former also has prehensile hair like Nightmare Moon does. The notion in the above theory that Nightmare Moon is an embodiment of dark magic possessing Luna is also similar to Sthertoth possessing Rukifellth, as Luna seems to remember being Nightmare Moon.
 * Nightmare Moon could be the embodiment of Luna's jealousy. This would be similar to Emerald's transformation into a dragon in Sailor Moon R, except that Emerald is destroyed along with her dragon form.
 * Nightmare Moon has also been compared to Maleficent, as she says "Stand back you foals" to the guards, which echoes Maleficent's line "Stand back you fools"
 * Nightmare Moon might have been inspired in part by Nightmare, the main villain of Kirby's Adventure, whom Kirby fights on the moon. She also may have been inspired by the G1 villain Tirek, as the two share many similarities.
 * Luna's appearence drastically changes between the first two episodes and Luna Eclipsed. She becomes taller with a more slender build, a darker coat, and a translucent mane and tail filled wih stars, greatly resembling her sister Celestia. This may be due to her regaining power that was drained from her after getting hit by the Elements.
 * When Princess Luna is restored, Nightmare Moon seems to shatter to pieces, as pieces of what is believed to be the evil of Nightmare Moon are shown laying around Luna after the Elements are used on her. King Sombra is also shattered to pieces, as well as G1 villain Lavan.