Three weeks after Thanos used the Infinity Stones to disintegrate half of all life across the universe,[N 1] Carol Danvers rescues Nebulaand Tony Stark from deep space. They return to Earth and join the remaining Avengers—Natasha Romanoff, Bruce Banner, Steve Rogers, Rocket, Thor, Pepper Potts, and James Rhodes. They track down Thanos to an uninhabited planet where he is living alone as a humble farmer. Thanos tells them that he destroyed the Infinity Stones so that nobody can reverse the culling of the Universe, and the energy backlash of that action left him scarred and crippled. Thor decapitates Thanos.
Five years later, Scott Lang escapes from the quantum realm[N 2] and finds Romanoff and Rogers at the Avengers‘ compound. Lang suggests travelling back in time via the quantum realm to thwart Thanos in the past. They ask Stark to develop a time machine for them, but Stark refuses because he has a young daughter and is worried what messing with the timeline might do to her. The Avengers instead turn to Bruce Banner, who has now gained control over his Hulk aspect and can become the Hulk without losing his intelligence. Banner agrees to help. Banner tells them that they can’t alter history, but they can instead retrieve the Infinity Stones from the past and reverse the disintegration in the present. Banner struggles to construct a working time machine until Stark, who has changed his mind, helps him complete the project.
Romanoff travels to Japan to retrieve Clint Barton, who has become a vicious vigilante, and brings him back to the Avengers headquarters. Banner and Rocket Raccoon travel to Norway, where the survivors of Asgard have established a small fishing community. There they find Thor, who has become a fat drunk. After some argument, Banner convinces Thor to rejoin the Avengers.
Barton tests Banner and Stark’s time machine and successfully travels back in time for a few minutes, proving that the plan is viable. The Avengers split into several groups for their mission. Banner, Rogers, Lang, and Stark travel to New York City in 2012.[N 3] Banner visits the Sanctum Sanctorum and convinces the Ancient One to give him the Time Stone, but she warns him that after the Avengers are done using them, they must return the Stones to their original time frames to prevent the Universe from breaking down. Rogers manages to steal the Mind Stone, but Lang and Stark’s attempt to steal the Space Stone fails and Loki escapes with it. Rogers and Stark use the last of their size-altering Pym Particles to travel to SHIELD’s secret base under Camp Lehigh in 1970.[N 4] They steal the Space Stone from SHIELD’s vault, as well as some vials of Pym Particles from Hank Pym‘s lab so they can return to the present.
Rocket and Thor travel to Asgard in 2013 to retrieve the Reality Stone from Jane Foster,[N 5] and Thor obtains his former hammer, Mjolnir.[N 6] Barton and Romanoff travel to Vormirin 2014 and learn from the Soul Stone’s keeper, the Red Skull, that it can only be acquired by sacrificing someone they love. After a brief struggle, Romanoff sacrifices herself and Barton returns to the present with the Soul Stone. On Morag in the same year, Nebula and Rhodes steal the Power Stone before Peter Quill can.[N 7] Rhodes returns to the present with the Power Stone, but before Nebula can return, her cybernetic implants overload as her mind connects to her past self. Thanos uses this connection to access future-Nebula’s memories and thereby learns of the Avengers’ plans. Past-Nebula disguises herself as future-Nebula and travels to the future as a spy.
Banner and Thor construct a new Infinity Gauntlet, and Banner uses it to restore everyone whom Thanos disintegrated. While this is happening, past-Nebula uses the time machine to transport Thanos and his ship to the present day, and he obliterates the Avengers headquarters with an aerial bombardment. Thanos tells them that he will use the Infinity Stones to destroy the Universe and create a new, better one, and nobody will remember the old one. The Avengers fight him, but they are no match for him; he overpowers all of them and summons his army to lay siege to Earth. At this moment, Stephen Strange arrives with reinforcements, which include the resurrected Avengers and Guardians of the Galaxy, along with his fellow sorcerers and the armies of Asgard, Wakanda and the Ravagers, to the compound to fight Thanos and his army. Meanwhile, future-Nebula convinces the past version of her sister Gamora to leave Thanos and to help her to fight him. Danvers eventually joins the battle too, destroying Thanos’ ship. Stark uses the Infinity Stones to disintegrate Thanos and his army. However, the energy feedback kills Stark.
Following a funeral for Stark, Thor appoints Valkyrie as the queen of New Asgard and joins the Guardians of the Galaxy. Rogers returns the Infinity Stones and Mjolnir to their original places in time, but instead of returning to the future he stays in the past to be with his old girlfriend Peggy Carter. In the present, an elderly Rogers passes on his shield to Sam Wilson.