Henry Pym has destroyed all remains of Ultron-5 and his technology, but Ultron has already uploaded his mind to a new body, Ultron-6, who takes control of most Iron Man's armors, while at the same time goes to the S.H.I.E.L.D. Helicarrier and probes Maria Hill's brain to get the access codes for S.H.I.E.L.D.'s nuclear arsenal.
Thor is unaware of all this, in the Enchantress' paradise world. He enjoys to be with her until realizes the Avengers may still need his help and asks the Enchentress to send him back to Earth. The Enchantress gets bitter and angry, yet complies.
The Avengers face Ultron at the Helicarrier, but Ultron has self-reparation abilities and also shoots a beam that reverts Hulk to Bruce Banner. Ultron then proceeds to fire all nuclear missiles to wipe humanity. Thor arrives to help the Avengers, and while Ultron is distracted fighting, Iron Man and Hill try to disarm the missiles, but Ultron prepared for that contingence and had them locked up. At the end, it's Ant-Man who disables Ultron by downloading logic in his brain: if he was created by a human, it means he's as flawed as humanity. This logic deactivates Ultron and unlocks the missiles, allowing for them to be disabled.
While Wasp congratulates Hank for saving the world, Hill criticizes him because the world was in danger because he created Ultron to begin with, to which Hank sadly agrees.