Nightmare Moon

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

- Nightmare Moon

Ni ghtmare Moon is the villain of My Little Pony: Friendship is Magic, and the main antagonist of the two-part pilot episode "Friendship is Magic". 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, but sleep through the 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 transformed her into the "Mare of the Moon", Nightmare Moon. In devestation and to protect Equestria, Celestia used the Elements of Harmony to banish Nightmare Moon to the moon, and it's said that in a thousand years, on the longest day of that year, Nightmare Moon will make her return.

Return of Princess Luna
She makes her return at the Summer Sun celebration in the place of Princess Celestia; Twilight was the only pony who realized her return, but could not tell anyone as Celestia, her tudor, encouraged her to make friends instead of worrying about the story. Twilight and her soon-to-be friends chased Nightmare Moon into the forbidden Everfree Forest, where after conquering many obstacles, Twilight had to find the "spark" that would make a 6th 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 Elements only existed in the hearts of her friends. That spark triggered the final element: Magic. Using the Elements of Harmony, Twilight activated a spell that struck Nightmare Moon, exorcising 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 act, and was given forgiveness. Later at the celebration (held by Pinkie Pie), the other ponies even forgave Luna with a flower necklace.

Nightmare Night
In the season 2 episode "Luna Eclipsed", Princess Luna returns to Ponyville during the holiday, Nightmare Night. Her appearence has changed in this episode. She is now taller and more slender build, a darker coat, and a translucent mane and tail. Luna, with Twilight's help, tries to change her image from that of the terrifying Nightmare Moon, to a favorable one as Princess. However 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 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.

Other appearances
Luna has a few cameos in season 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.

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. However, this theory was proven wrong when it was revealed that Celestia and Luna defeated Sombra in the past and imprisoned him.

Trivia

 * Nightmare Moon's backstory and her goal of bringing eternald 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"