S.H.I.E.L.D. Director Nick Fury (Samuel L. Jackson) arrives at one of his agency's facilities during an evacuation. The Tesseract, an energy source of unknown potential, has activated. It opens a portal through space and the exiled Norse god Loki (Tom Hiddleston) steps through. Loki takes the Tesseract and also takes control of the minds of several SHIELD personnel, including Dr. Erik Selvig (Stellan Skarsgård) and Agent Clint "Hawkeye" Barton (Jeremy Renner), to aid him in his getaway. As SHIELD personnel pull out of their base, some pursuing Loki and others merely fleeing, the ground beneath the base collapses and it's destroyed.
In response to the attack, Fury re-activates the Avengers Initiative. First he pulls Agent Natasha Romanoff (Scarlett Johansson), a.k.a. the Black Widow, out of an interrogation (tied to a chair, she seems to be the victim rather than the interrogator, but appearances are deceiving). Fury sends her to India to find and recruit Dr. Bruce Banner (Mark Ruffalo), a.k.a. the Hulk. At the same time Agent Phil Coulson (Clark Gregg) approaches "Iron Man" Tony Stark (Robert Downey Jr.) and requests that he review Dr. Selvig's research. Fury himself approaches Steve Rogers (Chris Evans), a.k.a. Captain America, with an assignment to retrieve the Tesseract from Loki. During his exile, Loki encountered the Chitauri, an alien race seeking to conquer the galaxy. In exchange for the Tesseract, the Chitauri agree to help Loki subjugate Earth.
Suiting up, Captain America and Iron Man travel to Germany to apprehend Loki, who is recovering iridium needed to stabilize the Tesseract's power, and demanding that the civilians kneel before him. Loki quickly surrenders when the two heroes arrive, and he is escorted to a SHIELD helicarrier, a high-tech, flying aircraft carrier. However, Thor (Chris Hemsworth), Loki's half-brother and the Norse God of thunder, arrives and attempts to free Loki so he can reason with him on his own, but he gets into a fight with Iron Man and Captain America. The fight ends in a stalemate. Eventually, Loki is taken to the helicarrier and placed in a glass cell designed to hold the Hulk. Fury explains that if Loki attempts to escape, even by merely cracking the glass, a shaft will open below him and he'll plummet to Earth and possibly be killed.
The Avengers, now brought together, argue and deliberate over how to approach Loki and the revelation that SHIELD plans to harness the Tesseract's power to develop weapons, a discovery made by Rogers. Fury admits that the events in New Mexico a year before (recounted in Thor) made SHIELD aware of other races on other worlds, some of whom may see Earth as an easy target. The decision was made to produce weapons with the Tesseract as a means of deterrence. As the group argues, Clint Barton and Loki's possessed agents attack the helicarrier, disabling one of its engines in flight. While Stark and Rogers attempt to restart the damaged engine, Romanoff tries to prevent Dr. Banner from turning into the Hulk and destroying the ship from inside. Her attempt fails and she's chased through the ship until Thor takes up the battle to pacify the beast and manages to fell him briefly with a hit from his hammer, Mjolnir. While fighting Barton, Romanoff slams him into a guard rail, and the blow to the head breaks Loki's mind control. After the Hulk falls from the ship, Thor is tricked into Loki's holding cell by Loki himself, who has recovered his scepter and releases the cell and allows Thor to plummet. Loki is held at bay briefly by Agent Coulson who is also tricked by one of Loki's holographic projections - Coulson is stabbed in the back by the real Loki. Coulson later shoots Loki with a blast from an unidentified weapon, one that harnesses the power of the Destroyer. Coulson dies while Fury tries to save his life. Thor escapes from the cell a split second before it hits the ground. Banner wakes up in his human form after crashing into an abandoned factory.
Fury uses Coulson's death to motivate the Avengers to work as a team. Stark and Rogers realize that simply defeating them will not be enough for Loki. He needs to overpower them in a very public way so as to validate himself as ruler of Earth. Using a device built by Dr. Selvig, Loki opens a portal to the Chitauri home world over Manhattan, summoning a Chitauri invasion.
The Avengers rally in defense of New York, but quickly come to the conclusion that they will be overwhelmed as wave after wave of Chitauri descend upon Earth. With help from the reformed Barton, Captain America and Thor evacuate civilians while Dr. Banner transforms into the Hulk and goes after Loki, beating him into submission in Tony Stark's penthouse. Romanoff makes her way, with a little help from the Chitauri, to the device that holds the portal open (conveniently located on the roof of the Stark Building) and hits Dr. Selvig over the head, freeing him of Loki's control. Dr. Selvig reveals that Loki's staff can be used to close the portal.
Meanwhile, the council overrides Fury and scrambles a jet that fires a nuclear missile at Manhattan to end the invasion. Iron Man intercepts the missile and directs it at the portal and the Chitauri base before running out of oxygen and plummeting back to Earth, but the Hulk catches him as he falls. A dazed Stark, awakened by the Hulk's roar, offers to take the team out for shawarma, but they decide to apprehend Loki first. Thor escorts Loki and the Tesseract back to Asgard, while Fury notes that the Avengers will go their separate ways until a new world-threatening menace emerges.
In a mid-credits scene, the Chitauri leader the Other tells his master that it is futile to attack Earth, as fighting the Avengers is like courting death. His master turns, revealing himself to be Thanos.
After further credits, the Avengers are shown eating together in a shawarma joint; the team looks worn out and no one speaks.