After Starlight's graduation, Trixie convinces Starlight to celebrate with some wine. An awful lot of drinks later, Starlight decides to try her hoof at some new magic and selects a spell at random from an old book of Starswirl's and casts it.
Then the Four Horses of the Apocalypse show up.
Luckily, they're pretty cool dudes about the whole deal.