This is how Megatron's defeat goes in Friendship is Magic.
[The Autobots and ponies arrived at the ruin of the Princesses' old castle]
Megatron: You're kidding. You're kidding right?
[Twilight finds herself in a dark space and before her stand the Thirteen]
Twilight Sparkle: The Thirteen.
Prime: We have been watching you for a long, long time.
Other Prime: You have fought for Optimus, our last descendant, with courage and with sacrifice, the virtues of a leader, a leader worthy of our secret. The Matrix of Leadership is not found. It is earned. Return now to Equestria. Defeat Megatron. It is and always has been your destiny.
[A bright light blinds Twilight and Twilight finds herself back in the Castle of the Royal Pony Sisters and the Matrix of Leadership is around her neck in chains.]
Twilight Sparkle: The Matrix!
[The Matrix glows]
Megatron: What trickery is this?
Twilight Sparkle: It's no trickery.
[The Matrix glows brighter]
Twilight Sparkle: Matrix of Leadership,
Optimus Prime: I saw the signs of Megatron's return and I knew it was you who had the magic inside to defeat him, but you could not unleash it until you let true friendship into your heart. Now if only another will as well. Megatron!
Optimus Prime: It has been a thousand years since I have seen you like this. Time to put our differences behind us. We were meant to rule together, big brother.
Twilight Sparkle and Rainbow Dash: Brother?
Optimus Prime: Will you accept my friendship?
Megatron: I'm so sorry! I missed you so much, little brother!
Optimus Prime: I've missed you, too.