In 2018, twenty-three days after Thanos erased half of all life in the universe, Carol Danvers rescues James Rhodes, Pepper Potts, and Nebula from deep space and they reunite with the remaining Avengers—Bruce Banner, Steve Rogers, Thor, Natasha Romanoff, and Happy Hogan—and Rocket on Earth. Locating Thanos on an uninhabited planet, they plan to use the Infinity Stones to reverse his actions, but discover Thanos has already destroyed them to prevent further use. Enraged, Thor decapitates Thanos.
Five years later, Scott Lang escapes from the Quantum Realm. With help from Daisy Johnson, Lang reaches the Avengers Compound and explains that he experienced only five hours while trapped. Theorizing that the Quantum Realm allows time travel, they ask the reluctant Rhodes and Potts to help them retrieve the Stones from the past to reverse the actions of Thanos in the present. Rhodes, Potts, Rocket, Johnson, and Banner, who has since merged his intelligence with the Hulk's strength, build a time machine. Banner notes that altering the past does not affect their present; any changes create alternate realities. Banner and Rocket travel to Norway, where they visit the Asgardian refugees' settlement New Asgard and recruit an overweight and despondent Thor. In Tokyo, Romanoff recruits Clint Barton, who became a vigilante after his family was erased during the execution of Thanos' plan.
Banner, Lang, Rogers, Rhodes, Potts, and Johnson time-travel to New York City during Loki's attack in 2012. At the Sanctum Sanctorum, Banner convinces the Ancient One to give him the Time Stone after promising to return the various Stones to their proper points in time. At Stark Tower, Rogers retrieves the Mind Stone from Hydra sleeper agents, but Rhodes, Potts, and Lang's attempt to steal the Space Stone fails, allowing 2012-Loki to escape with it. Rogers, Rhodes, Potts, and Johnson travel to Camp Lehigh in 1970, where Rhodes, Potts, and Johnson obtain an earlier version of the Space Stone and encounter the deceased Tony Stark's father, Howard. Rogers steals Pym Particles from Hank Pym to return to the present and spies his lost love, Peggy Carter.
Meanwhile, Rocket and Thor travel to Asgard in 2013; Rocket extracts the Reality Stone from Jane Foster, while Thor gets encouragement from his mother, Frigga, and retrieves his old hammer, Mjølnir. Barton, Romanoff, Nebula, and Hogan travel to 2014; Nebula and Hogan go to Morag and steal the Power Stone before Peter Quill can, while Barton and Romanoff travel to Vormir. The Soul Stone's keeper, Red Skull, reveals it can only be acquired by sacrificing a loved one. Romanoff sacrifices herself, allowing Barton to get the Stone. Hogan and Nebula attempt to return to their own time, but Nebula is incapacitated when her cybernetic implants link with her past self, allowing 2014-Thanos to learn of his future self's success and the Avengers' attempt to undo it. 2014-Thanos sends 2014-Nebula forward in time to prepare for his arrival.
Reuniting in the present, the Avengers place the Stones into a gauntlet that Rhodes, Potts, Banner, Rocket, and Johnson have built. Banner, who has the most resistance to their radiation, uses the gauntlet to undo every one of Thanos' disintegrations. Meanwhile, 2014-Nebula, impersonating her future self, uses the time machine to transport 2014-Thanos and his warship to the present, which he then uses to destroy the Avengers Compound. Present-day Nebula convinces 2014-Gamora to betray Thanos, but is unable to convince 2014-Nebula and kills her. Thanos overpowers Rhodes, Potts, Thor, a Mjolnir-wielding Rogers, and Johnson, and summons his army to retrieve the Stones, intent on using them to destroy the universe and create a new one. A restored Stephen Strange arrives with other sorcerers, the restored Avengers and Guardians of the Galaxy, the Ravagers, and the armies of Wakanda and Asgard to fight Thanos' army. Danvers also arrives and destroys Thanos' warship, but Thanos overpowers her and seizes the gauntlet. Rhodes steals the Stones and uses them to disintegrate Thanos and his army, but mortally wounds himself as he does so.
Following Rhodes' funeral, Thor appoints Valkyrie as the new king of New Asgard and joins the Guardians. Rogers and Johnson return the Stones and Mjølnir to their proper timelines and Rogers remains in the past to live with Carter while Johnson returns to the present. In the present, an elderly Rogers passes his shield to Sam Wilson.
