Not long after Megatron’s demise and the restoration of Cybertron, the Autobots celebrate as Optimus Prime promotes Bumblebee to warrior class. The festivities end, however, when Optimus sets out on a journey to find the AllSpark, the source of new life on Cybertron, and takes Wheeljack with him to find it so that new Transformers can come into being. Ultra Magnus is left in charge in Prime’s absence to hunt down the missing Shockwave and Starscream with the other Autobots. Meanwhile, on Earth, at the bottom of the ocean, Megatron’s consciousness is reawakened by Unicron, who seeks to destroy his arch-enemy Primus, the very core of Cybertron, and requires Megatron’s body to do so. Unicron reformats Megatron’s lifeless husk into a perfected body with new upgrades before heading to Cybertron. In the meantime, Ultra Magnus and Smokescreen continue to search for the fugitive Decepticons in the Sea of Rust, but are soon attacked by the Predacons Skylynx and Darksteel. After a brutal fight, Magnus is severely damaged and Smokescreen is barely able to save his life and make it through an emergency space bridge with him. The damage is so critical that the Autobots are forced to call in Ratchet from Earth for assistance while the Autobots deduce that the two new Predacons must be creations of Shockwave. Meanwhile, Shockwave and Starscream are revealed to have restarted “Project: Predacon” and plan to create an army with Skylynx and Darksteel being their first creations.
Set on finding answers, Bumblebee leads Smokescreen, Bulkhead and Arcee to track Predaking, who has taken refuge near the grave site of hundreds of ancient Predacon bones, and ask his help in finding his two new brothers. However, Predaking refuses, having not forgiven the Autobots for destroying his brethren on Earth. Bumblebee, after asking the inprisoned Knock Out for any ideas on locating the fugitives, he leads the Autobots to Megatron’s old fortress Darkmount located in the Decepticon capital called Kaon to find answers, but they are soon confronted by Unicron in Megatron’s body. The Autobots believe Megatron returned before Unicron corrects them. Unicron battles the Autobots, who are outmatched and are forced to the lower levels where Bulkhead, Arcee, and Smokescreen almost fall into a smelting pit. However, time bought by Bumblebee allows the Autobots to escape through a Ground Bridge portal. Unicron, enraged by his failure in his weak form, decides that he needs a greater weapon.
Meanwhile, in the Theta Scorpii asteroid belt, Optimus and Wheeljack arrive in Ultra Magnus’s ship where the AllSpark – which itself is pure energy stored in a container of Alpha Trion’s creation – is adrift. Optimus heads out to find it, but is soon troubled with a plasma storm. Despite Wheeljack’s insistence to turn back, Optimus keeps going and eventually retrieves it, though their ship is damaged by an asteroid, and they set course of Cybertron. Meanwhile, the Autobots try to contact Optimus from the former Decepticon flagship Nemesis, but the asteroid damage destroyed their transmitter, making the contact only one way. With Optimus not available and Ultra Magnus wounded in action, Bumblebee assumes temporary leadership of the Autobots.
Elsewhere, Predaking starts investigating and finds the area where the two Predacons fought Magnus and Smokescreen, realizing that the Autobots were telling the truth and begins searching for Skylynx and Darksteel, but is found by Unicron. Megatron within, who seeks to have his body back, deceives Unicron into talking to him, withholding Predaking’s betrayal to him. Predaking, believing Unicron to be Megatron, immediately attacks him, but Unicron turns the tables and quickly beats him down before reading his mind and finding the bone yard. Unicron then puts Megatron under eternal suffering for his deception. Meanwhile, Shockwave, Darksteel, Skylynx, and Starscream find the Predacon bone yard, but are soon confronted by Unicron, who they assume is Megatron until he clarifies who he is once more. Darksteel and Skylynx charges at Unicron for conflict, but he easily defeats them. Unicron then uses the power of Dark Energon to resurrect the Predacons into undead Terrorcons. They end up scaring Starscream away before attacking Shockwave, who holds them off before being overpowered. Meanwhile, the Autobots detect Megatron’s signal through Unicron, and also detect the Terrorcons, which are headed for the Well of All Sparks, the most direct route to Primus himself.
Bumblebee decides to lead a counterattack with Bulkhead, Smokescreen, and Arcee on the Nemesis, while Ratchet stays back at Kaon with Ultra Magnus. However, Starscream sneaks aboard the ship, and frees Knock Out and the few captive Vehicon troops, and tries to retake the ship, intending to use it to flee Cybertron. As Bulkhead and Arcee kill the Vehicon troops, Starscream is about to neutralize Bumblebee using the Immobilizer, only to be betrayed and ironically, knocked out by Knock Out, who once again tries to join the Autobots and is accepted this time. Meanwhile, Predaking arrives at the bone yard where he finds Skylynx and Darksteel, who reveal the remains of their fallen brethren are resurrected by Unicron. Predaking orders them to help him reclaim the remains, but they refused, resulting in a brawl with Predaking as the winner. Not long after, the brutally mangled and scarred Shockwave arrives and suggests that they help the Autobots instead, who then leaves to parts unknown.
At the Well of All Sparks, Unicron’s undead army arrives, but the Nemesis confronts and attacks them, and the Predacons soon join them. After a brief firefight, the Nemesis is shot down just above the Well, which gives an imprisoned Starscream a chance to escape. As Unicron charges their way, the Predacons join the Autobots in an alliance. Predaking, Skylynx and Darksteel attempt to fight off the Terrorcons using their fire-breath, only to be forced into the Well with them. At that point, Optimus and Wheeljack return, but Unicron shoots the ship down, although both survive, with the wounded Wheeljack getting rushed by Bulkhead and Arcee to help him. Optimus briefly engages Unicron, and tries to snap Megatron out of his possession, but to no avail. Unicron eventually gets the upper hand and prepares to kill Optimus. However, Bumblebee uses the Polarity Gauntlet to stop him while Optimus attends to the AllSpark. Bumblebee eventually loses his strength as Unicron overpowers him, before following Optimus and shooting him down. Unicron is about to destroy the Allspark, only to find the container empty when opening it. Realizing too late that it was a trap, Unicron is rendered helpless as his Anti-Spark is pulled into the device, sealing him forever inside it. With the link to Unicron severed, all of the Terrorcons are destroyed, and Megatron regains control of his body. However, as Starscream returns and tries to talk him into re-igniting the war, Megatron reveals that his time under Unicron’s control has soured him towards tyranny, and so he no longer wishes to be a Decepticon. When Starscream presses the issue, Megatron angrily disbands the Decepticons altogether, and flies off to start a new life. Starscream then flies back to Darkmount to take control of the Decepticons once again by reviving the cause in his name, only to be confronted by the Predacons, intent on getting revenge for their abuse. His, Darksteel’s and Skylynx’s fates are revealed in the sequel series, Transformers: Robots in Disguise.
In the aftermath, Optimus reveals to the Autobots that he emptied the AllSpark into the Matrix within him, but can no longer be separated from either, requiring him to sacrifice himself to completely restore Cybertron. The Autobots try to dissuade him, but Optimus states that the Matrix cannot be restored again, and that the age of Primes is over, but recognizes each Autobot – even Knock Out – as a Prime in their own right before taking off into the core as the Autobots watch. As Optimus plunges into Primus, millions of sparks of all the deceased and unborn Transformers emerge from the Well, including Prime’s own spark. The film’s final moments mirror Optimus’ last words, as he states that his sacrifice will mark a new beginning rather than the end to anything – “simply put, another transformation”.