In the opening, Clint Barton is teaching his daughter archery on his secluded farm while his wife prepares a picnic lunch for them. Suddenly, Clint's daughter vanishes and the rest of Clint's family disintegrates, along with half of all life across the universe, the result of Thanos' snapping his fingers after acquiring all six Infinity Stones. Nebula and Tony Stark are stranded in space following their defeat by Thanos on Titan, but are returned to Earth by Carol Danvers and reunited with Natasha Romanoff, Bruce Banner, Steve Rogers, Rocket, Thor, and James Rhodes. The team formulates a plan to steal the Infinity Stones back from Thanos and use them to reverse his actions, but learn upon finding him that he had used the stones a second time to destroy them, preventing their further use. He tells the remaining Avengers that he did so to avoid using the Stones for further nefarious purposes. Enraged, Thor cuts off Thanos' head, saying it's what he should have done in Wakanda.
Five years later, Scott Lang escapes from the quantum realm to discover that his daughter Cassie is now a teenager and that Hope van Dyne, along with half of the population, has disappeared in the snap. Rogers has been leading grief counseling sessions for survivors still struggling with the effects of the snap, while Romanoff is tirelessly keeping watch over both Earth and the rest of the universe with the help of Rhodes, Danvers, Okoye, Rocket, and Nebula. Lang goes to Romanoff and Rogers, and explains that while five years had passed for them, only five hours had passed for him in the quantum realm and the difference in time factors there. The three go to Stark, who is now raising a child with Pepper Potts, and explain their theory that the quantum realm can be used to go back in time and steal the Infinity Stones before Thanos is able to collect them. Stark initially rejects their proposal with concern about risking his family and the peace he has found, but after reflecting upon the loss of Peter Parker decides to test theoretical models that would work with Lang's quantum tunnel, eventually finding one that works.
With Stark now on board with the plan, the remaining Avengers set out to reassemble their team. Bruce Banner has now embraced the Hulk as a part of him, and has melded his own consciousness and the Hulk's together into one. Romanoff, after hearing reports from Rhodes of an assassin that operates with similar methods to Barton, goes the Japan to track him down. Barton, consumed with grief after the loss of his family, has been operating under the mantle "Ronin" while brutally massacring cartels and gangs in order to try and improve the world that's still left. Natasha finds him in Japan and after some convincing, he agrees to rejoin the team in order to try and bring his family back. Banner and Rocket go to the small town of New Asgard, where Valkyrie and the last survivors of Asgard have settled. They there find Thor, who has become overwhelmed by guilt over failing to kill Thanos in Wakanda. Thor has become overweight, his hair and beard are overgrown, and he spends his free time eating junk food, getting drunk, and playing Fortnite with his friends Korg and Miek. Thor begrudgingly agrees to return to the Avengers after some convincing from Rocket and Banner.
After testing the quantum time machine on Barton, who confirms that it works, The Avengers are reunited with a plan - Banner, Rogers, Lang, and Stark embark to retrieve the Time, Mind, and Space stones during the battle of New York in 2012. Banner goes to the Sanctum Sanctorum, where he is informed by the Ancient One that taking the Time Stone from her time line would prevent Stephen Strange's future efforts to stop Kaecilius from destroying the laws of nature. She eventually concedes the Time Stone to Banner after he informs her that Strange had given Thanos the stone in his time line, implying Strange had intended for a specific sequence of events to occur for Thanos to be defeated. Banner also promises the stones' return to their proper time lines in order to prevent any ill effects. Lang and Stark attempt to steal the Space Stone after the Avengers confiscate it from Loki. Lang gives Stark's past self a cardiac arrest by pulling a circuit in his artificial heart, while Stark steals the briefcase housing the Tesseract when nobody is looking. Their plan is thwarted when Stark drops the briefcase after he is accidentally hit by the Hulk. Loki then steals the Space Stone and uses it to escape custody. Rogers succeeds in stealing the Mind Stone from undercover Hydra agents, but stumbles across his past self, who mistakes him for a disguised Loki. After defeating past-Steve, Rogers meets back up with Stark and Lang, who now must figure out another way to get the Space Stone without running out of the limited supply of Pym Particles that allow them to travel through the quantum realm. Lang returns to the present with the Mind Stone while Rogers and Stark devise a plan to steal the Space Stone from a U.S. Army installation in the 1970s, while stealing further vials of Pym Particles in order to make the journey back home. While there, Rogers sights Peggy Carter and Stark has an meaningful conversation with his father Howard.
Rocket and Thor travel to Asgard to retrieve the Reality Stone before Malekith uses it against the Nine Realms. While in Asgard, Thor is reminded that his mother, Frigga, would die soon and has a chance encounter with her while Rocket steals the Aether, the vaporized version of the Reality Stone, from Jane Foster. The two return to Earth after Frigga counsels Thor and he retrieves his hammer Mjolnor, elated to discover that he is still worthy of it. Nebula and Rhodes travel to Morag to steal the Power Stone before Peter Quill does. As Rhodes returns to the present with the Power Stone, Nebula malfunctions and remains on Morag. With two consciousnesses operating on Nebula's systems, Thanos and Ebony Maw discover the presence of future Nebula and go to kidnap her. Nebula realizes what has happened and tries to warn the others, but is too late. Thanos scans her memories and discovers the Avengers' plan, and sends the more loyal past Nebula back to the present as a spy. Barton and Romanoff travel to Vormir to retrieve the Soul Stone, though are conflicted when Red Skull, keeper of the Soul Stone, informs them that the stone can only be retrieved by sacrificing someone they love. The two fight over which will make the sacrifice, with Romanoff ultimately taking the fall, while a distraught Barton returns to Earth with the Soul Stone.
After everyone has returned to the present on Earth, Stark, Rocket, and Banner set out to craft a gauntlet to wield the stones, one constructed from the same nanotech of Stark's latest Iron Man suit. Banner volunteers himself to wield the gauntlet and bring back everyone that disappeared in Thanos's snap, reasoning that he can withstand both the gamma radiation and the immense pain brought on by using the stones. He succeeds, though they are almost immediately attacked by Thanos, who has been brought to Earth by the impostor Nebula, destroying the quantum portal in the process. Thanos reduces the Avengers headquarters to rubble, splitting the team up and causing the gauntlet to fall into Barton's protection. The past Nebula is killed by her future self as she attempts to take the Infinity Stones from Barton, while Rogers, Thor, and Stark confront Thanos, who decides he will instead use the Infinity Stones to destroy the universe and create one in his vision. The three fight Thanos one on one, with Rogers confirming Thor's theory that he is worthy of wielding Mjolnor, but are each bested by Thanos. Soon after Thanos' army lands on Earth, T'Challa appears before Rogers, along with all of the Avengers and other allies revived by Banner, before launching an assault on Thanos and his army. After a lengthy battle during which Stark is reunited with Parker and Quill is reunited with past Gamora, Thanos wrestles with numerous Avengers for the Infinity Stones. When he's bound by Wanda Maximoff's energy, Thanos orders Glaive to have his ship fire multiple energy blasts, nearly devastating the Avengers' efforts. Captain Marvel reappears, taking out Thanos' ship while fighting for control of the gauntlet. Using the nanotech from the new gauntlet, Stark maneuvers the Infinity Stones from Thanos' hand to his own and uses them to turn Thanos and his entire army into dust, triumphantly stating "I am Iron Man." Parker and Potts console Stark as he dies from exposure to the Stones' radiation.
Following the battle, The Avengers hold a funeral for Stark, whose Mark I arc reactor is floated out on the lake next to his house. Barton and Wanda Maximoff take solace in the fact that Romanoff and Vision, who did not return in the snap, would be proud of their victory over Thanos. Thor makes Valkyrie the Queen of Asgard and joins the Guardians of the Galaxy in order to find his true purpose, free of the burden of royalty and leadership for the first time in his life. Barton returns home to his family and Parker returns to school, where he is reunited with his best friend Ned. Meanwhile, Rogers is tasked to go into the past to return the stones and Thor's hammer to their original time lines, but decides not to return to the present and to instead live the rest of his life in the past with Carter. He reappears before Sam Wilson and Bucky Barnes as an old man, and passes his shield and the mantle of Captain America on to Wilson. A brief flashback shows Rogers and Carter finally sharing the dance they never got to have in their living room, truly happy at last.