An extraterrestrial race called the Chitauri wants the powerful Tesseract cube (introduced in Captain America The First Avenger movie) which is in custody of S.H.I.E.L.D. Loki, half brother of the mighty god of thunder Thor, who seeks revenge against mankind for his defeat in the hands of his brother, accords with The Other, Chitauri's leader, to obtain the cube for them in exchange for using the Chitauri's army to attack and subdue the Earth.
Under the influence of Loki (as seen in the post-credit scene from the Thor movie), scientist Dr. Erik Selvig unconsciously triggers the cube to transport Loki into Earth. The God of Mischief easily defeats S.H.I.E.L.D.'s forces including Nick Fury and Maria Hill, and escapes with the cube, bringing with him Hawkeye (agent Clint Barton) and Selvig, both under hypnosis. S.H.I.E.L.D.'s base is destroyed in the process.
Iron Man (Tony Stark), Bruce Banner (AKA the Incredible Hulk), and Captain America (Steve Rogers) are called by Fury to find the cube and capture Loki. Along with the Black Widow (agent Natasha Romanoff), Iron Man and Captain America capture the bandit in Paris (where Cap clashes in hand combat with Loki, is logically overpowered but Iron Man defeats the villain). In their way back to S.H.I.E.L.D.'s Hellicarrier (a huge aquatic-flying base), Thor, sent by Odin, releases Loki from the heroes' custody and tries convincing his half brother to stop his evil ways and return to Asgard.
Devising the unwise attack plan of basically "attacking", Iron Man rams Thor into a forest where they match their strength and power in fight; Loki doesn't escape but stays to enjoy his brother being punched. It is Captain America who cools the two heroes. They finally bring Loki into S.H.I.E.L.D.'s custody, and lock him in an unbreakable prison cell built for the Hulk. But Loki isn't carrying the cube and its location remains unknown.
Nick Fury told the heroes that the Tesseract cube was to be used to generate clean and inexpensive energy for the world. But Tony Stark, Bruce Banner, and Captain America discover that the agency's plan was to create powerful weapons. As the heroes commence arguing, disliking each other for various reasons, Hawkeye (still under hypnosis) and a group of highly trained assassins assault the Hellicarrier destroying one of its engines, and disabling other vital aspects of the ship, now in risk of collapsing.
Iron Man and Captain America work together to bring stability back to the ship. Bruce Banner cannot control his temper and turns into an angry Hulk who rampages through the ship almost smashing the Back Widow, and overcoming Thor's vain attempts to control the monster by pure force. Hulk leaves the ship following a jet plane that fired upon him.
Meanwhile, Loki escapes from his cell, tricking Thor who gets locked in it, and lets the cell go dooming Thor to a serious fall but he manages to break free before impact. Agent Coulson discharges a S.H.I.E.L.D. Tesseract weapon against Loki, but can't survive the wound inflicted earlier by the villain and passes away in front of Nick Fury. Finally, Black Widow knocks Hawkeye unconscious, releasing him from Loki's influence.
Loki escapes, the Hellicarrier is in ruins, Thor and Hulk are missing, Coulson is dead and to make matters worse, Selvig (still under Loki's commands) uses the cube to open a portal right above Stark's skyscraper building in New York City, letting the Chitauri army invade our planet and attack.
It's when Nick Fury launches the Avengers Initiative, his plan to gather the most remarkable and powerful individuals as an invincible group to defend the Earth when the threat is too large to confront in any other way. And so Iron Man, Hulk, Thor, Hawkeye, and Black Widow, following Captain America's lead, join forces to defeat the Chitauri army and Loki.
The battle is spectacular. The Earth team fights side by side to defeat the enemy. Hulk destroys the army's largest attack vessel, while his teammates destroy alien soldiers one by one or by the dozen. But the Chitauri army seems never ending. So the world government orders the launch of an atomic missile against New York City, a missile Nick Fury fails to intercept.
Putting his typical selfness apart, Iron Man grabs the missile and brings it with him through the portal into the Chitauri's mother ship, destroying it. This deactivates all alien soldiers and ships. At the same time, Selvig (no longer under Loki's influence) and the Black Widow successfully control the cube by using Loki's staff to close the portal. Iron Man's armor fails completely, Tony Stark faints, and falls down to Earth through the portal just before it fully closes. It is the Hulk who catches Iron Man in mid air.
Surrounded by his new found friends, Stark wakes up and uttering jokes, celebrates that the battle is over and the Avengers have won.
But... Where's Loki? Oh, he's in Stark's office, crawling out of the hole made by his own body when the Hulk smashed him to the ground as if he were a club (one of the funniest scenes in the movie). The full Avengers team surrounds Loki to guarantee that he's not escaping again.
Finally and with Nick Fury's consent, Thor brings Loki and the Tesseract cube to Asgard. The other Avengers go their separate ways knowing they will assemble again if a new extraordinary need requires them to.
Epilogue 1 (halfway through the credits): The Chitauri Other decides the humans are too powerful; to face them is to court death. The person he’s talking to turns around and smiles. It’s Thanos.
Epilogue 2 (at the very end): The Avengers are seen at a cheap restaurant, unenthusiastically eating shawarma (a Middle Eastern sandwich) as Tony Stark had suggested as a joke at the end of the battle scene.