My headcanon:
It starts when Twilight destroyed the windigos. It is known that the windigos had learned how to steal the ponies’ magic by draining negative emotional power and turning it into cold and ice, creating a self-destructive process that was halted with positive emotional magic generated by the ponies themselves. When Twilight destroyed them, an opening was created as the ponies started arguing with each other, letting the inner magic out to the surroundings. This could not be fixed without changing the essence of the ponies themselves.
Opaline had developed the ability or a spell that enables her to take other people’s cutie marks and thus can steal magic to keep under her control. She then began to sow discord among the ponies living in the shadow of a caste system based on magic which then created an identity conflict between the ponies based on race. This is no longer found in G5, but it was very much alive while Twilight was living with her friends. Despite everything the Mane 6 does, such underlying tendencies from very old times could not be healed in time.
Twilight realized that magic had to be brought under control, the Ponykind have become a serious threat to the world with their bickering and conflicts that might have caused non-ponies to make serious threats. Then she also had to stop magic stealing from Opaline who may become an alicorn during the turbulent times and may have tried to do something very dangerous to everyone. So she created the Unity Crystals that only the alicorns can control, likely with the non-ponies’ permission. Also, Opaline had to be stopped by taking away all her magic, since she had developed parasite-like abilities.
Opaline was defeated by Twilight who took her magic into the Unity Crystals, blocking her alicorn powers which can only be broken out with powerful magic and putting her under house arrest in chains. In the following centuries, Opaline had to spend her time in the dark castle. Twilight had undoubtedly visited her repeatedly, only to have to return each time Opaline would not allow herself to be reformed.
Meanwhile, Twilight was busy steering Equestria into better times, devoting much of her work to international affairs and developing a global society like our world after the year 1945 - but her friends died, one by one, and although new friends were made, immortality became a heavy burden for her. Possibly she had spent much of her free time studying the Unity Crystals and the magic, and may have discovered much that is not yet known. Maybe the dead heroines aren’t quite dead, at least for her.
She may have had visions of the future that she could more easily interpret unlike Celestia, and learned about the Mane 5. So she made a blanket that splits into three, gave one to Argyle’s family who may be in her circle (perhaps Luster Dawn) - and concealed the other two with her alicorn powers. She knew that her successor is on the way, thus spending the last few centuries creating a better world for everyone, ponies and non-ponies alike.
Then came the collapse of Equestria. The valley where Canterlot and Ponyville were located had been developed into a metropolis, when something completely unexpected happened; the entire Everfree forest except for the lower parts of the valley disappeared, Ponyville disappeared, and Canterlot’s surroundings collapse into ruins and remains that are covered with vegetation in later times. Canterlot came under attack, was evacuated amid chaos, and was left partly in ruins, hidden from the outside world by a sea of fog.
The magic just disappeared and general confusion reigned among the ponies who then tried to gather all the knowledge and lore they could salvage, but they may have been subjected to memory wipe which created huge gaps that are filled with false memories. Twilight disappeared. And three crystals fell to the ground from a new shooting star that the ponies focused all their attention on, before they forgot why. The whole world seemed to have collapsed, all trade ceased, the tribes split apart as they possibly accused each other of loss of magic. Non-ponies evacuated Equestria which may have been quarantined, probably on the orders of Spike among the dragons, in response to the loss of magic.
My interpretation is that the Everfree finally revealed its secrets. It was never explained why middle Equestria was a no man’s land for a long time until the ponies went there, driven from their homeland by the windigos. The Griffons owned the land, which they still did not want to exploit, and later sold it to the ponies. It could be because this was where Tambelon was located. The capital of the Dark Empire from Grogar’s time - and his home.
First Grogar destroyed the Everfree, neutralizing the Harmony tree, then he gathered his monsters from all over the world to wreak havoc and attack Canterlot where Discord met him. Grogar even without the bell was so strong, he maimed Discord and sought out Twilight who realized that the dark magic based on fear and terror was too strong for her and her friends.
Twilight fought Grogar, but realized that the ponies were too frightened and too badly in disarray for her to draw support from them, and the monster hordes were too overwhelming. The whole world was about to fall into the hands of the tyrant, Celestia and Luna may have ascended and thus cannot help, while Cadence or Fluffy Heart were too far away. All hope seems lost. But Twilight came up with the vision she had, her successor which could be the element of Hope.
So she took out the Unity Crystals, clear about the risk she was taking - and split it, thus gaining access to all magic from around the world. She could not defeat Grogar, but she could banish him and his monsters, purged Equestria of all monsters into a temporary prison (perhaps Tartarus) that Grogar will break out of sooner or later. Then she saved the Ponykind, the whole world - and bought them time for her successor to arrive.
But the price will be high. She is “banished” for her crime of sealing the magic so that Grogar cannot return, sending the world into very uncertain times. It is possible that she transformed into a star, perhaps she ascended towards her final destiny, and later let the Unity Crystals fall to the ponies, divided into three - the earth pony crystal for Argyle’s family, the unicorn crystal in Bridlewood and the pegasi crystal to the royal family of Zephyr Heights.
Grogar will break free and take over the entire world (Equus), and Twilight knowing this will happen had undoubtedly “programmed” the crystals to react to Sunny under certain criteria. She also put in a hologram that could be intelligent, because she hadn’t forgotten Opaline and the threat she represents.
Since then, she waits for Sunny to come to her, when the time for the showdown with Grogar comes. Meanwhile, Opaline will fight with Sunny, test the new alicorn who will then learn how to use her powers and reunite Equestria as well as contact the rest of the world to restore what was lost. With the return of magic, Grogar can break out, but Twilight had bought valuable time for the New Mane 6 and their friends to be ready for the worst and most dangerous enemy in history. Twilight will then disappear, let Sunny take the lead.