Following the events from Thor: Ragnarok, Thanos, and his team invade Thor's mother ship in search of the Tesseract. That powerful cube, first seen on Captain America: The First Avenger, holds the Space Stone, one of the six Infinity gems Thanos is after.
None of the Asgardians are a match for the villains and lay dead or barely alive, including the God of Thunder. Unscratched, Loki, who, unbeknown to Thor, stole the Tesseract from Asgard before its destruction, propitiates a hand combat between Hulk and the mad titan. Surprisingly, the gamma-spawned powerhouse is no match for Thanos, who beats him almost effortlessly. With his last breath, Heimdall sends the Hulk to Earth using Bifrost capabilities. And Loki dies strangled by Thanos after he gets a hold of the gem.
The villain leader sends his four minions to Earth in search of two Stones and uses his newly gained power to destroy the mother ship and teleport to safety.
On Earth, Hulk lands in Dr. Strange's Sanctum Sanctorum, turning into Bruce Banner. After explaining about Thanos to the Master of the Mystic Arts and Wong, they reach out to Tony Stark, who was jogging in the park with fiancee Pepper Potts. Back in the mansion, Wong explains the group about the Infinity Stones, mighty colorful gems created at the dawn of the cosmos. Whoever holds all of them at once could obliterate life with but a gesture. Strange has one of them in the Eye of Agamoto: The Time Stone.
Suddenly, a tremor and strong winds follow. Outside, people running in panic. An immense circular-shaped starship floats over Manhattan. Peter Parker sees it while on a school bus - driven by Stan Lee, and sneaks past his classmates to swing in that direction.
From the ship emerges Cull Obsidian, a tall, muscular monster, and Ebony Maw, a telekinesis master. Banner tries turning into the Hulk, but cannot. Tony puts on his newest suit - which forms from a device on his chest, and along with Spider-Man and the two magicians, fights back. But their opponents are genuinely formidable and kidnap Strange, bringing him into their ship. Iron Man and Spider-Man follow secretly. Banner calls Steve Rogers for help.
In outer space, Star-Lord and his group are flying in response to an SOS call. They locate the Asgardians' mother ship, destroyed. A terrible-looking scene with people floating all over the place. One of them is Thor. They bring him inside.
After waking him up, Thor devises a plan to fight Thanos back. He, along with Rocket and Groot, travel in a capsule to Nidavellir - a place of legend where they conceived Mjolnir, to create a weapon capable of killing Thanos. And Star-Lord with Gamora, Drax, and Mantis would go to Knowhere to retrieve the Reality Stone from the Collector before Thanos could claim it.
Meanwhile, Wanda Maximof (alias the Scarlett Witch), and Vision (with a human appearance) are in their apartment, somewhere in Europe. Vision lets Wanda know about alerts he is been getting from the Mind Stone (attached to his forehead). As they learn about the events in New York, they're attacked by the skilled Thanos warriors, Proxima Midnight and Corvus Glaive. The heroes would have lost if not by the timely help from Captain America (or Nomad, his name after the Civil War event), Black Widow and the Falcon. The villains take off, defeated. But Vision is left in terrible shape.
Star-Lord, Gamora, Drax, and Mantis find Thanos in Knowhere as he's pressing the Collector to give away the Reality Stone. Gamora, his adopted daughter, skillfully kills Thanos. But it was all a trick. Using the powers of the gem, he reverts things to normal, defeats the heroes, and takes Gamora with him.
Cap and his group meet with James Rhodes, alias War Machine, and after dismissing an order from General Thunderbolt Ross to lock Steve Rogers away, they board a Quinjet to Wakanda. Their idea is to use the technology in Black Panther's realm to disconnect the Mind Stone from the Vision and destroy it so Thanos could not become omnipotent.
Inside Ebony Maw's ship, a tortured Dr. Strange gets rescued by Iron Man and Spider-Man, who dispose Maw into the cosmos and perish in the cold void. The starship eventually lands on Titan, the Saturn moon, which used to be Thanos hometown, now in ruins. There, the Guardians of the Galaxy suddenly attack them. But the quarrel ends soon as the two bands realize they're after the same guy. Dr. Strange uses the Eye of Agamoto to discover a way to defeat Thanos and finds a single opportunity for over 14 million possible future outcomes. They get ready for the clash.
Thanos has Nebula prisoner. He tortures her to get Gamora to reveal the location of the Soul Stone. Once she does, father and adopted daughter travel to Vormir, the new home of the Red Skull (casted away by the Tesseract after he unsuccessfully tried to hold it- again, in Captain America: The First Avenger). The Red Skull explains that the Soul Stone requires his wielder to give away what he loves the most. With honest tears in his eyes, Thanos pushes Gamora to a precipice, causing her death, and gets the gem.
Meanwhile, Thor, Rocket, and Groot reach Nidavellir. But, Thanos shut it down after they created the Infinity Stones gauntlet for him. Only Eitri, the Dwarf King, stayed alive. Thor and Rocket turn the Nidavellir star-powered machinery on for Eitri to forge a mighty mallet, Stormbreaker. And Groot donates his arm to form the handgrip.
In Wakanda, Black Panther and his army along with Steve Rogers, Black Widow, Falcon and the "White Tiger" (Bucky Barnes/Winter Soldier), witness as Proxima Midnight, Cull Obsidian and their legion of monsters try penetrating the city's force field. In the lab, Shuri reconfigures the Mind Stone to disconnect it from the Vision without killing him, while the Scarlett Witch watches over them.
Realizing the enemy could eventually attack from all fronts, King T'Challa orders to open a small door in the force field to let the aliens invade. That way, the heroes could counterattack more efficiently. Banner, still unable to turn into the Hulk, uses Tony's Hulkbuster armor to aid in the fight. An awful battle follows.
In Titan, Iron Man, Spider-Man, Dr. Strange, the Guardians and Nebula almost defeat Thanos. But he eventually prevails and gets the Time Stone from Dr. Strange, who exchanges the gem with Tony's life.
On the Wakanda battlefield, the enemy files outnumber the righteous ones. As they're about to savor defeat, Thor's new hammer brings renovated hope, unstoppable through alien lines.
The God of Thunder and the Scarlett Witch turn the balance in favor of the heroes. Banner kills Obsidian; Wanda, Midnight, and Vision, kill Corvus Glaive. The Avengers stand victorious. But now, they must face Thanos.
The Mad Titan appears wielding five of the six Stones. Vision begs Wanda to destroy the sixth one on his forehead. She reluctantly proceeds as they profess their love for each other. Everyone tries to slow Thanos down, giving Wanda the possibility of shuttering the Stone in time. But Thanos uses the Time Stone to revert to when the gem was intact, and removes it from the Vision's forehead, who falls broken and inert.
Thanos achieves his goal: He holds all six stones in the gauntlet.
But Thor attacks him, severely wounding him in the chest with Stormbreaker. Muttering, Thanos reminds Thor that he should have hit him in the head instead, and snaps his fingers. Reality changes and half of the universe's living beings perish, turning into ashes.
His gauntlet broken, Thanos teleports away as some heroes vanish: Bucky Barnes, Falcon, Scarlett Witch, Black Panther, Groot, Mantis, Drax, Star-Lord, Dr. Strange and Spider-Man. Those still standing cannot overcome the dominant feeling of defeat and loss.
In another planet, Thanos, still hurting, sits down to watch the sun come up, as he rejoices for accomplishing his goal: to re-balance the universe by reducing the number of the living in half, securing natural resources. He rejoices despite having lost it all: His team, his army and his dear daughter, Gamora.
-- In a post-credits scene, Nick Fury sends an alert to Captain Marvel before he and Maria Hill turn into ashes.