In the Eastern European country of Sokovia, the Avengers – Tony Stark, Steve Rogers, Thor, Bruce Banner, Natasha Romanoff, and Clint Barton – raid a Hydra outpost led by Baron Wolfgang von Strucker, who has been experimenting on humans using the scepter previously wielded by Loki. They encounter two of Strucker's experiments – twins Pietro, who has superhuman speed, and Wanda Maximoff, who can manipulate minds and throw energy blasts – and apprehend Strucker, while Stark retrieves Loki's scepter.
Stark and Banner discover an artificial intelligence within the scepter's gem, and secretly use it to complete Stark's "Ultron" global defense program. The unexpectedly sentient Ultron, believing he must eradicate humanity to save Earth, eliminates Stark's A.I. J.A.R.V.I.S. and attacks the Avengers during a victory party at their headquarters. Escaping with the scepter, Ultron uses the resources in Strucker's Sokovia base to upgrade his rudimentary body and build an army of robot drones. He recruits the Maximoff twins, who harbor a grudge against Stark for weapons responsible for their parents' deaths, and together, they visit the South African shipyard base of arms dealer Ulysses Klaue to obtain vibranium. The Avengers battle them, but Wanda subdues the heroes with haunting visions, causing the Hulk to run amok and forcing Stark to use his powerful "Veronica" armor to stop him.
A worldwide backlash and the doubts and fears Wanda's hallucinations have caused send the team into hiding at Barton's safehouse farm, where they meet Barton's wife, Laura, and children. Thor departs to consult with Dr. Erik Selvig on the meaning of the apocalyptic future he saw in his hallucination. Realizing an attraction between them, Romanoff and Banner plan to flee together after fighting Ultron. Nick Fury arrives and encourages the team to form a plan to stop Ultron. In Seoul, South Korea, Ultron forces Banner's friend Dr. Helen Cho to use her synthetic tissue technology together with the scepter's gem to create the perfect body for him. When Ultron begins uploading himself into the body, Wanda is able to read his mind; discovering his plan for human extinction, the Maximoffs turn on Ultron. Rogers, Romanoff and Barton hunt Ultron and retrieve the synthetic body, but Ultron captures Romanoff.
The Avengers fight amongst themselves when Stark secretly uploads J.A.R.V.I.S. – who is still operational after hiding inside Ultron on the internet – into the synthetic body. Thor returns to help activate the body with lightning, explaining that the gem on its brow – one of the six Infinity Stones, the most powerful objects in existence – was part of his "vision". Taking "Vision" as its name, the robot and the Maximoffs join the Avengers, and the team heads for Sokovia, where Ultron has used the vibranium to build a machine to lift a large part of the city skyward, intending to crash it into the ground to cause global extinction. As the city begins to lift, Banner rescues Romanoff, who awakens the Hulk for the battle. The Avengers fight Ultron's army while delaying Ultron from activating his plan's final procedure. Fury arrives in a Helicarrier with Maria Hill, James Rhodes and S.H.I.E.L.D. agents to assist in evacuating civilians, but Pietro dies when he shields Barton from a barrage of fire. A grieving Wanda abandons her post to destroy Ultron's primary body in revenge, inadvertently allowing one of his drones to activate his machine. The landmass plummets, but Stark and Thor overload the machine and shatter the city into pieces. In the aftermath, the Hulk, unwilling to endanger Romanoff by being with her, departs in a Quinjet, while the Vision confronts Ultron's last remaining body and appears to destroy it.
Later, the Avengers have established a new base in upstate New York, run by Fury, Hill, Cho, and Selvig. Fury assures Romanoff that Banner likely escaped the crashed Quinjet. Believing the Mind Stone is safe with the Vision, Thor returns to Asgard to learn more about the forces he suspects have manipulated recent events. Stark and Barton retire from the team, and Rogers and Romanoff prepare to train new Avengers: Rhodes, Wanda Maximoff, the Vision, and Sam Wilson.