Twenty-three days after Thanos used the Infinity Gauntlet to disintegrate half of all life in the universe, Carol Danvers rescues Tony Stark and Nebula from deep space and returns them to Earth. They reunite with the remaining Avengers—Bruce Banner, Steve Rogers, Rocket, Thor, Natasha Romanoff, and James Rhodes—and find Thanos on an uninhabited planet. They plan to retake and use the Infinity Stones to reverse the disintegrations, but Thanos reveals he destroyed them to prevent further use. An enraged Thor beheads Thanos.

Five years later, Scott Lang escapes from the quantum realm. He travels to the Avengers’ compound, where he explains to Romanoff and Rogers that he experienced only five hours while trapped. Theorizing that the quantum realm could allow time travel, the three ask Stark to help them retrieve the Stones from the past to reverse Thanos’ actions in the present, but Stark refuses to help. After talking with his wife, Pepper Potts, Stark relents and works with Banner, who has since merged his intelligence with the Hulk’s strength and body, and the two successfully build a time machine. Banner warns that changing the past does not affect their present and that any changes instead create branched alternate realities. He and Rocket go to the Asgardian refugees’ new home in Norway to recruit Thor, now an overweight alcoholic, despondent over his failure in stopping Thanos. In Tokyo, Romanoff recruits Clint Barton, now a ruthless vigilante following the disintegration of his family.

Banner, Lang, Rogers, and Stark travel to New York City in 2012. Banner visits the Sanctum Sanctorum and convinces the Ancient One to give him the Time Stone. Rogers successfully retrieves the Mind Stone, but Stark and Lang’s interference inadvertently allows 2012 Loki to escape with the Space Stone. Rogers and Stark travel to S.H.I.E.L.D. headquarters in 1970. Stark obtains an earlier version of the Space Stone, encountering his father, Howard, in the process, while Rogers steals several Pym Particles from Hank Pym to return to the present. Rocket and Thor travel to Asgard in 2013, extracting the Reality Stone from Jane Foster and retrieving Thor’s hammer, Mjolnir. Nebula and Rhodes travel to Morag in 2014 and steal the Power Stone before Peter Quill can. Rhodes returns to the present with the Power Stone, but Nebula is incapacitated when her cybernetic implants link with those of her past self. Through this connection, 2014 Thanos learns of his future success and the Avengers’ attempts to undo it. Thanos captures present-Nebula and sends past-Nebula to the present in the former’s place. Barton and Romanoff travel to Vormir, where the Soul Stone’s keeper, the Red Skull, reveals it can only be acquired by sacrificing someone they love. Romanoff sacrifices herself, allowing Barton to obtain the Soul Stone.

Reuniting in the present, the Avengers fit the Stones into a Stark-created gauntlet, which Banner uses to resurrect all those whom Thanos disintegrated. 2014 Nebula uses the time machine to transport 2014 Thanos and his warship to the present, where he attacks the Avengers’ compound, planning to destroy and then rebuild the universe with the Stones. Nebula convinces 2014 Gamora to betray Thanos, and Nebula kills her past self. A restored Stephen Strange arrives with other Masters of the Mystic Arts, the restored Avengers and Guardians of the Galaxy, the armies of Wakanda and Asgard, and the Ravagers to fight Thanos and his army alongside Danvers, who destroys Thanos’ warship as she arrives. After overpowering the heroes, Thanos seizes the gauntlet, but Stark steals the Stones back and uses them to disintegrate Thanos and his army. Stark then dies from the energy emitted in the process.

Following Stark’s funeral, Thor appoints Valkyrie as the king of New Asgard and joins the Guardians of the Galaxy, while Quill searches for 2014 Gamora. Rogers returns the Infinity Stones to their original places in time and remains in the past to live with Peggy Carter. In the present, an elderly Rogers passes on his shield and mantle to Sam Wilson.

However Doctor Strange stubs his toe a few days after and decides “fuck it this timeline counts as a loss as well”.