Let me start out by saying this is merely conjecture. Anyone looking for canon MCU facts should divert their article-reading attention elsewhere.
So, on to the article... As the majority of us know, at the end of Avengers, the Asgardian trickster Loki was taken down by Earth's mightiest heroes. He was then taken back to Asgard by his brother Thor and then the events of Thor: The Dark World happened, which I will get into later.
Back up a little bit to the end of the first Thor movie. Loki let go of Thor's hand and fell into the abyss. Between that and the opening scene of The Avengers, he came into contact with the Other, and perhaps Thanos directly. It was then that they formulated a plan. Thanos needed the Tesseract (one of the infinity stones), and Loki was the perfect pawn to acquire it. Those are the facts.
This is where the speculation begins. Loki is not the one to stand aside and take orders. He must have demanded something out of the deal. Sure, you can say that Loki's main prize was to rule over Earth after he had invaded with the Chitauri, but Loki is also not one to settle. In the first Thor, he had his heart set on the throne of Asgard, the throne which he thought of as rightfully his. However, after the battle on the Bifrost bridge with Thor, he couldn't just stride right into Asgard with open arms,he would need a more devious method.
The easiest option would to be taken aboard as a prisoner. He has already shown that he's familiar with this tactic since he gave up to Captain America and Iron Man in Germany. He was taken aboard the S.H.I.E.L.D. helicarrier as a prisoner but it was soon realized that he wanted to be captured, as it allowed him to break up the Avengers along with the help of a brainwashed Hawkeye and a squad of operatives.
You would think that Thor would learn. After the whole intentional prisoner stunt on the helicarrier, Thor once again takes Loki as his prisoner and brings him back to Asgard, which is exactly where Loki wants to be. It only sweetens the deal that Thor takes the Tesseract as well. This way not only can Loki hold up his end of the deal with Thanos, but he can work his magic to take the throne.
Loki must have known that Asgard is never truly at peace with the rest of the realms. He knew that at one point, Thor was going to need his help to overcome some unconquerable foe and then Loki could hatch his plan.
Now to the events of Thor: The Dark World. The film starts out with Loki still in captivity, but eventually Asgard is inevitably attacked, this time by the ancient Dark Elves. Of course, Thor comes to Loki for help, and Loki agrees. It turns out that the Dark Elves are searching for yet another one of the infinity stones, called the Aether. During the quest to intercept the Aether, an epic battle occurs in the Dark Realm, during which Loki is stabbed through the torso by a dark elf named Kurse and dies.
Spoiler Alert: He doesn't die.
Instead, he takes the form of an Asgardian soldier and returns to Asgard to proclaim his own death to Odin. After a few unknown events, Loki is up on the throne, disguised as Odin himself. So basically, why would Loki even want Earth if Asgard was his end goal? It's simple, he didn't care about Earth. He just needed Thor's attention (might as well attack the planet that Thor's girlfriend is on) so that he could return to Asgard.
There was another reason that Loki might have attacked New York in the haphazard way that he did. Not only did he get Thor to show up, and not only did he get the location of the Tesseract, but he exploited the strongest that Earth could offer. Thanos is enough of an evil genius to not just have his eyes set on the infinity stones, he needs to also know of any opposition to dispose of. Loki brought out not only Thor, but Hawkeye, Black Widow, Captain America, Iron Man, and the Hulk. Now Thanos knows about his enemies and the Avengers have no idea that Thanos exists.
So now what? (Small Guardians of the Galaxy Spoiler)
Now that Loki is finally upon the throne of Asgard, he is in possession of both the Tesseract and Thanos' Infinity Gauntlet, which can be seen n the vault in the first Thor movie. There's the big question now of what he's going to do with him. Is he going to go the power-hungry route and challenge Thanos like Ronan did in Guardians of the Galaxy, or is he going to be a good little Asgardian and cooperate?
I personally believe in the latter. Since Ronan went the first route, I sincerely doubt that Marvel is going to do the same thing with an even more well-known villain. Obviously Thanos is eventually going to end up with all of the infinity stones and become some unstoppable baddie that requires every available hero to combat. Loki's probably going to supply him with the Tesseract, and a few other thugs are going to hunt down the remaining five.
Loki is currently not scheduled to appear in Avengers: Age of Ultron, so we're probably going to have to wait until the third Thor to see how this plays out for Loki.