Warning! Major spoilers for the Infinity Wars event ahead!

The Asgardian Trickster God Loki Laufeyson has always been a complex creature, constantly wavering between villain and hero, and consistently trying to figure out how he can write his own destiny. In the recent Infinity Wars saga Loki is at the center of the heroes' fight against Requiem and the Infinity Stones, believing that with their power he can figure out who is controlling his future. Eventually, a disenchanted Loki gains total control of the stones, before seemingly giving them up to the heroes, saving two worlds with one action.

The Infinity Wars event saw Requiem, revealed to be a vicious soul-bereft Gamora, able to collect the six stones and use their power to create Warpworld, a new world within the Soul Stone. Simultaneously, Loki is on the hunt, looking for who has made it so that his destiny is to always be the villain. While perusing the library in Omnipotence City Loki finds no records of any of his heroic deeds, and when the librarian Flowa gives him a book of alternate universe Loki histories, he finds that many pages have been ripped out. This leads Loki and Flowa to investigate at the God Quarry before Loki eventually teams up with the heroes who are trying to stop Gamora.

Related: Marvel Reveals [Spoiler] Killed Thanos in Infinity Wars

After Gamora traps Loki and other heroes in Warpworld, he is eventually able to break free from the binds of the world and collect a team of heroes to go back to their universe and fight Requiem. This group consisting of Loki , Emma Frost, Hulk, Ant-Man, Kang the Conqueror, and Ms. Marvel are able to find another set of Infinity Stones in the Wastelands and use them to finally defeat Gamora. Loki then betrays the team, switching out all of the stones for regular rocks, and uses them to enter another universe to confront the Celestials, who he believes are the ones writing his destiny.

Loki betraying his team during Infinity Wars.

Once in the Prime universe Loki addresses his so-called "puppet masters," asking the Celestials to show him his future. The Celestials, surprisingly, are more than willing to show Loki his future, but once he see's it he bursts out laughing in defeat, before stating "Well, I can see when I'm beat," and returning to the team he had abandoned. Once there Ant-Man accuses him of betraying them all and using them for his own selfish ends before Loki willingly hands the six stones over to the group of heroes so they can restore the main universe and the Warpworld universe before they both collapse.

After the two worlds are saved by the actions of the Infinity Stone-wielding heroes, Flowa can be seen in the library of Omnipotence City finishing up writing a book based on the events of Infinity Wars, including Loki's major part in saving both worlds. Loki was able to not only help save two worlds by giving up the Infinity Stones he possessed, but he also finally has a record of him doing something heroic in the Omnipotence library, hopefully firmly cementing his status as an anti-hero in the story of the universe.

More: Steve Irwin's Son Dresses As Loki With Real Life Alligator Variant For Halloween