The opening scene shows Unicron, a space-roaming artificial planet, grinding and consuming the peaceful robot planet Lithone, along with the vast majority of its civilians. Only one ship escapes, with Kranix and his crew as its only survivors, though they are later executed by the Quintessons. A second ship with Arblus aboard almost escapes, but is sucked into Unicron. Following the opening credits, the narrator states that the evil Decepticons control the Transformers' homeworld, Cybertron. The heroic Autobots are readying themselves on two of Cybertron's moons for a strike against the Decepticons, preparing a supply shuttle for launch to Autobot City on Earth. Their transmission is intercepted by the Decepticons, who ambush the shuttle and kill its crew, consisting of Ironhide, Ratchet, Prowl, and Brawn to use the ship to infiltrate Autobot City on Earth without being detected.
Meanwhile, on Earth, Daniel Witwicky and Hot Rod race to greet the shuttle. They notice its damaged exterior and spot Decepticons aboard the damaged shuttle, upon which Hot Rod fires at the stowaways. After a brief battle pitting Hot Rod and Kup against the Decepticons Blitzwing and Shrapnel, the Decepticons begin their attack on Autobot City. The outnumbered Autobots, including Autobot City Commander Ultra Magnus, Blurr, Springer, Perceptor, and female Autobot Arcee, fare poorly. Ultra Magnus sends orders to alert Blaster to radio for assistance from their commander and leader Optimus Prime. An attempt to thwart the transmission by Decepticon Soundwave fails, and the broadcast reaches Moon Base One where Optimus is stationed. Optimus Prime and the Dinobots arrive to successfully repel the Decepticon invaders, including the unstoppable Devastator. Optimus faces Megatron in a battle that leaves Optimus mortally wounded and Megatron severely damaged. The Decepticons retreat with Megatron and their other war-wounded loaded aboard Astrotrain for transport back to Cybertron, on the orders of Starscream.
Inside Autobot City's walls, Perceptor alerts the other Autobots that the wounds that Optimus Prime has suffered during his battle with Megatron are fatal. The dying Optimus Prime calls on Ultra Magnus to assume command of the Autobots and bestows him with the Autobot Matrix of Leadership, which Optimus extracts from his chest. Optimus asserts that the Matrix one day will light the Autobots darkest hour, right before he dies. Back in space, Astrotrain's shortage of fuel prompts the Decepticons to eject the dead weight of their injured — including the protesting Megatron. This leaves the remaining Decepticons to bicker among themselves for leadership.
Drifting aimlessly, the Decepticon castoffs encounter Unicron, who offers to give Megatron and the others new bodies on the condition that they destroy the Autobot Matrix, which, Unicron says, is the only thing that can stand in his way. Megatron reluctantly agrees, and Unicron uses his power to kill Megatron off, recreate, and reformat him as Galvatron, with his damaged underlings fashioned anew into Cyclonus, Scourge, and the Sweeps. Unicron provides them with a craft on which they travel to Cybertron, where Galvatron confronts and obliterates the treacherous Starscream and takes command of the Decepticons, as his alter-ego Megatron did before him.
Back on Earth, the Autobots are alerted as Unicron consumes Cybertron's two moons, along with Autobots Jazz, Bumblebee, Cliffjumper and Daniel's father Spike (who are ultimately rescued). Galvatron leads the Decepticons in another assault on Autobot City. The Autobots board a pair of shuttles and flee toward their threatened planet of Cybertron. Hot Rod, Kup and the Dinobots are shot down over the planet Quintessa, while Ultra Magnus and company evade their pursuers and set down on the planet of Junk for repairs.
Captured by Quittessa guardsmen, Hot Rod and Kup witness the sentencing and execution of Orbilus and are then subjected to a trial by Quintesson executioners. Before the trial, they see Kranix, now Lithone's last survivor, who then tells them about Unicron, before he's taken away by the Quintessa guardsmen to be fed to the Sharkticons. At the trial, Hot Rod and Kup battle the Sharkticons with difficulty, but luckily, they are rescued only by the arrival of the Dinobots. Grimlock intimidates the Sharkticons to rebel against the Quintessons with ease, while the Autobots escape. With help from the Dinobots' new ally, Wheelie, the group locate a ship and depart for the planet of Junk to join the other Autobots.
Meanwhile, Galvatron finds and hunts down the Autobots on Junk. Ultra Magnus tries but fails to awaken the Matrix's powers, and then is obliterated to pieces by the Sweeps. Galvatron steals the Matrix, stating that he intends to use it to make Unicron his slave. The remaining Autobots are harassed by hostile Junkion natives, led by Wreck-Gar, until Hot Rod's party touches down to befriend them. The Junkion allies repair Ultra Magnus and volunteer a vessel to help the Autobots fight against Unicron.
Back in space, Galvatron attempts to subjugate Unicron using the Matrix but is unable to unleash its power. Unicron, seeing that Galvatron is underestimating him, transforms into a huge planet-sized robot and attacks Cybertron. As protest against this, Galvatron opens fire on Unicron, but Unicron simply swallows him up. Decepticon defenders scramble to counter Unicron's attack, but he destroys each one of them, including Shockwave, Dirge, Thrust, Ramjet, and countless others. As the Autobots reach the scene, Hot Rod crashes his ship into through the giant's eye and finding themselves separated within Unicron's body. At that time, Wreck-Gar and his Junkions fight back against Unicron, but Unicron crushes their only ship, although they survived.
Inside, Hot Rod fights the recently consumed Galvatron. Hot Rod secures his grip on the Matrix, and the power of The Matrix is unleashed, transforming him into Rodimus Prime. Rodimus unleashes its power to destroy Unicron from within, but not before he throws Galvatron deep into space, landing on the volcanic planet Thrull. Rodimus leads the other Autobots out of Unicron's body before it explodes, sprawling parts of the giant across the galaxy. Reclaiming Cybertron, the victorious Autobots declare the beginning of a new age of peace and happiness while the defeated Decepticons scramble away to a burned world called Chaar. Ultra Magnus decided to step down his position as leader of the Autobots, handing it over to Rodimus. The movie ends with Unicron's monstrous head circling Cybertron, a dark replacement for the two moons that once existed. The movie ends, the screen freezes, the credits roll as an extended version of the movie's theme song plays, then everything stops, followed by a fadeout.