Spoiler Alert! Avoid reading this post if you haven’t seen The Avengers.

No really, look away!

O.k., let’s talk about The Avengers, the highest grossing movie so far this year, and the movie on track to potentially unseat James Cameron’s Avatar as highest grossing movie of all time. Specifically, I want to talk about the writing and Loki, the film’s key villain. More specifically, I want to explain how Joss Whedon managed to write the perfect Xanatos Gambit.

For those who don’t know or didn’t click the link above, a Xanatos Gambit (named for the villain Xanatos from Disney’s Gargoyles cartoon) is a plan that literally cannot fail because win or lose, the villain wins. This is one of those “I wanted you to beat me all along” scenarios, where defeating the villain somehow means the hero still loses. This isn’t changing your plans to compensate or getting lucky, this is planning all along for every possible outcome to lead to what you want. And Loki in the Avengers does so perfectly.

First, let’s get some background on Loki, God of Mischief and Lies. Check out that title – he’s the god of lies. Now in both the Marvel cinematic and comic book universes, being a “god” doesn’t really make you the embodiment of whatever you’re the god of; the comic book universe DOES have those things (Death, Eternity, Aeon, etc.) and the cinematic universe may gain those things (based on the Thanos cameo), but generally Thor is not the embodiment of thunder, and Hercules isn’t the embodiment of strength, etc. It’s just what they’re really good at, because they are actually alien beings from another dimension. Loki, then, is not the embodiment of lies and mischief, but he’s really good at it.

Loki really has only one goal in life – take over Asgard. He wants to rule. He feels Thor, his half brother, is not fit to take over for Odin and he wants that power for himself. Loki does not care one wit about Midgard (aka Earth). He’ll put it in peril to distract Thor, but Loki is all about controlling Asgard. Re-read those last two sentences – Loki doesn’t care about Earth! So why, in The Avengers, is he trying to take over? That very question is asked by Tony Stark during the penthouse scene. Tony comes very close to puzzling it out, but Loki distracts him with his villainy goodness (badness?). Why does Loki was to rule Earth? And what Earth would be left to rule with the Chitauri tearing it all up? What throne is he looking for?

The answer, of course, is that Loki doesn’t want to rule Earth. He doesn’t care about it. He never did. He allowed himself to be captured, he allowed himself to be defeated (and yeah, Hulk smashed him good, but he didn’t have to stick around for the big fight). It was all part of his plan.

Let’s examine that plan: first, Loki appears and steals the tesseract. Why? Well, to set things in motion. He knew stealing the cube would cause Nick Fury to call in the Avengers. Remember the ending of Thor – he’s been spying on the whole operation for some time now. Then, Loki gets captured. He clearly could have escaped, but instead he let himself be taken. Cap and Tony mention this on the Quinjet just before Thor shows up, and Black Widow eventually gets from Loki what his plan is – to set off the Hulk on the helicarrier. Only Loki is the god of lies…you think he really got played by the Black Widow? Nope, he WANTED them to know what the plan was. Then when it happens, and the Hulk goes berserk, they blame it on Loki and it really brings the team together.

And that’s what Loki wanted.

See, Loki wanted them to defeat the Chitauri. He wanted to lose the battle in New York. Why? So he could be taken back to Asgard. That was his plan all along. He never cared about conquering Earth. He never cared about defeating the Avengers. He just wanted a ride back to his home, the place he DOES want to conquer. And he got it, first class accommodations right back to Asgard. You can even see the smirk at the end when he’s got the gag on. It’s in his eyes. He won, and the heroes all thought they did. What better than to beat your enemies and make them think they won?

Now you may ask why Loki would betray Thanos in such a way. I mean, Big Purple is no one to mess around with. But I think Thanos was the co-architect of this plan. Why? Because he wants Loki back in Asgard too. Just sending him back wouldn’t work – Loki has to be brought back by Thor so that Odin does not suspect he’s still working with Thanos. See, with Loki back in Asgard, and knowing that Odin feels incredibly guilty about Loki in general and usually lets him off with little more than a slap to the wrist, Thanos has the perfect operative within striking distance of the one thing in the whole universe he REALLY wants (well, more than Death).

What is it Thanos wants? Did you miss it when you saw Thor? It’s easy to miss, but…

That’s right…in Odin’t vault is none other than the Infinity Gauntlet. And now Loki is right there, and he broke into it before without much trouble. Loki losing to the Avengers was the best possible outcome for both Loki, who can now try to take over Asgard again, and Thanos, who now has potential access to the Infinity Gauntlet.

The bad guys won this round, and meanwhile the heroes are off eating Shwarma and thinking they won.

And all of this points to one thing – Joss Whedon is a fucking genius. This is Machiavellian planning at its best, and the payoff clearly won’t come until at least Thor 2 or Avengers 2. It’s a perfect set up, and with luck we’ll eventually see that the “win” in the Avengers was actually a loss. Of course, that’s not to say the heroes didn’t really win anything. They did…because while the battle was nothing more than an elaborate smoke and mirrors to get Loki back to Asgard, the formation of the Avengers is actually the biggest win for the side of good you could hope for.

It’s all about the long game, and writers who understand and can use it.