Cybertron is a planet inhabited by sentient robots fueled by a substance called Energon and fitted with transformation cogs, devices that allow them to transform into vehicles. In the city of Iacon, Orion Pax, a mining robot without a cog, sneaks into an archive and watches a documentary on the Primes, the first Cybertronians made directly by their creator Primus. Security guards catch Orion, but his best friend D-16 bails him out. Later, a cave-in occurs in the Energon mine where the two work, trapping fellow miner Jazz. While Orion and D-16 save him, their overseer, Darkwing, blames the incident on their superior, Elita-1, and has her demoted.
Cybertron's leader, Sentinel Prime, returns from an expedition to the planet's surface to find the Matrix of Leadership, an artifact of the Primes, the absence of which caused Energon to stop flowing, forcing the miners to extract it. Though unable to find it, he organizes a race as a reprieve for the population. To prove themselves as more than miners, Orion enters himself and D-16 illegally using jet packs but they lose. While Sentinel promises to reward them for boosting mining morale, Darkwing drags the two to garbage incineration, where they meet the eccentric B-127. After discovering a chip among the junk containing a distress message from Alpha Trion, one of the Primes, Orion convinces D-16 and B-127 to travel with him to his coordinates on the surface, later also persuading Elita to join after she catches them hitchhiking on a cargo train.
The four eventually find a deactivated Trion alongside the corpses of the other Primes. Upon reactivation, he reveals that Sentinel betrayed the Primes to steal the Matrix, which failed when it rejected him and disappeared, and has secretly been working for invading Quintesson aliens, giving them regular Energon supplies in exchange for letting him rule Cybertron while removing the miners' cogs to keep them subservient. Trion provides the group with cogs, allowing them to transform, and a chip carrying evidence of Sentinel's treason. Sentinel and his forces then arrive, capturing and killing Trion.
Evading their pursuers, the team travels back to Iacon to expose Sentinel but is captured by the High Guard, former warbots of the Primes rebelling against Sentinel. While D-16 takes command of the High Guard by defeating their leader, Starscream, Orion grows concerned by his friend's increasing aggression since learning the truth. Sentinel's forces find them, and in the ensuing battle, D-16, B-127, and half the High Guard are captured while the evidence chip is destroyed.
Orion, encouraged by Elita, rallies the remaining High Guard members and returns to Iacon to rescue their comrades. Once there, Orion convinces the miners to rebel while Elita exposes Sentinel by broadcasting the memory recordings of his lieutenant, Airachnid, throughout the city. After defeating Sentinel, Orion and D-16 argue over whether to execute him, until the latter accidentally shoots his friend. Though initially horrified, D-16 ultimately lets Orion fall to his death. Now calling himself "Megatron," he kills Sentinel and commands the High Guard to destroy Iacon.
Finding him worthy, Primus and the spirits of the Primes bestow Orion with the Matrix, reviving him as "Optimus Prime," who then defeats Megatron before exiling him and the High Guard. After the Matrix restores the miners' cogs and Cybertron's Energon flow, Optimus christens his followers as Autobots and sends a message warning the Quintessons to stay away. In a post-credits scene, Megatron renames the High Guard into the Decepticons and declares war on the Autobots.