Optimus Prime, leader of the Autobots, narrates the collapse of the Transformers' home world, Cybertron. It was rendered uninhabitable by war between the Autobots and the Decepticons. Led by Megatron, the Decepticons are searching for the AllSpark so they could use it to take over the universe. The Autobots want to find the AllSpark so they can use it to rebuild Cybertron and end the war. Megatron managed to locate the AllSpark on Earth, but crash-landed in the Arctic Circle and froze in the ice. After stumbling upon his frozen body in 1897, explorer Captain Archibald Witwicky accidentally activated Megatron's navigational system and his eyeglasses were imprinted with the coordinates of the AllSpark's location, an incident that left him blind and mentally unstable. Sector 7, a secret government organization created by President Herbert Hoover, discovered the AllSpark in the Colorado River and built the Hoover Dam around it to mask its energy emissions. The still-frozen Megatron was moved into this facility and was used to advance human technology through reverse engineering.
On the Island of Sodor, Thomas the tank engine is working hard but somehow, a portal to the human world opens and he, his friends, the Mane Six (Twilight Sparkle, Rainbow Dash, Rarity, Pinkie Pie, Fluttershy and Applejack) and Spike the dragon are transported to the world of the humans and Transformers. Dizzy from the trip between worlds, Thomas awakes to find Twilight and the others- Who stayed the way they were back on Sodor- standing before him. What's more surprising is that Thomas himself has transformed into a Prime! Suddenly, Pitch Black, a female Decepticon, appears and attacks Thomas. However, he manages to avoid several attacks and blocks her blasts using a forcefield. Having discovered his newfound abilities, Thomas fights Pitch, only to find that she can only speak French and does not speak English very well. After Thomas defeats Pitch, she reveals that she dislikes working with the Decepticons. Twilight reveals that Thomas is actually a Prime, who was the leader of the Trainbots, OpThomas Prime. However, Thomas recieves a call from an Autobot scout named Bumblebee and he sets out to join him. The others follow him, only to discover that a special cube known as the AllSpark is lying somewhere in this world. Twilight realizes that the only way they can get back to their home worlds and Thomas back to normal is to use the AllSpark to stop the Decepticons.
In the present day, the Decepticon known as Blackout attacks a U.S. military base in Qatar in order to find the location of Megatron and the AllSpark. He tries to hack into the files of the computer base but is stopped when the base commander cuts the computer hard lines. Captain William Lennox and his team manage to escape from the base and search for help. Back in the United States, Captain Witwicky's descendant Sam Witwicky buys his first car, which turns out to be the Autobot scout Bumblebee, who tries to help him woo his crush Mikaela Banes. Later, Sam catches a glimpse of Bumblebee's true form when he signals the other Autobots.
On Air Force One, another Decepticon named Frenzy infiltrates the plane and tries to hack into the network again, only this time is more successful until he is stopped by the U.S. intelligence operatives before he can retrieve the file information. Frenzy is then picked up by his partner Barricade, and they pursue Sam after discovering he has the glasses with the AllSpark's coordinates. Witwicky is rescued by Bumblebee, and Mikaela also learns of the Transformers' existence. Bumblebee fights Barricade and manages to subdue him while Sam and Mikaela decapitate Frenzy although he still survives and disguises himself as Mikaela's phone.
Meanwhile, Scorponok, who was sent by Blackout, fights Captain Lennox and his team, killing one of them and injuring another. During the battle, Scorponok is forced to retreat when he gets injured by sabot rounds fired on him by the U.S. Air Force. Lennox and his team then return to the United States and report their findings on the Decepticons to the Pentagon.
Sam and Mikaela, along with Thomas, his friends, The Mane Six and Spike, soon meet Optimus Prime and his other Autobot partners Jazz, Ironhide, and Ratchet. Optimus learns from Twilight that Thomas is the Prime who went missing several years ago the war broke out. Thomas also learns from Optimus that he was not built as an oridnary train like his friends on Earth but on Cybertron. Thomas soon begins to realize who he truely is and proceeds to continue to learn more about his past. Princess Celestia begins to have visions of the location of the AllSpark and Megatron. Rainbow Dash dislikes Optimus, thinking he is uncool and is just a bossy boots who does nothing. But one night, however, as she is scanning the city for any Decepticon activity, she disguises herself as another Decepticon and helps people but they think she's a villain. Optimus catches her off duty and corners her on a rooftop. As they fight, Optimus accidently knocks Rainbow's Decepticon helmet off, revealing who she really is. As Optimus is confused with this, Rainbow donkey-kicks him and he is thrown into a wall. As Optimus gets up, Rainbow says: "You are so smug! You know that? Well, you think this is always about victory with your sheepish talk about my friend's past and that whole "Find the AllSpark" thing. And you thought that we couldn't survive without the Great and Powerful Optimus Prime to help us through our problems. Well, I've got some news for you: We progressed just fine without you!". Optimus disagrees and says: "You aren't ready! You're narrow-minded and bad-tempered and more importantly, I'm better than you.". A fight breaks out between the two and then suddenly, Rainbow realizes what she has done and runs off. Optimus tries to run after her but is captured by Barricade and Frenzy. Rainbow informs the other Autobots, Bumblebee, Sam, Mikaela, Spike, Thomas, His friends, and the rest of the Mane Six. Thomas organizes a rescue mission and Sam fits him with a new Wrist Locator, which will help them learn the location of the AllSpark, Megatron and Optimus.
Frenzy, who was transported to the dam while in disguise, finds the AllSpark and contacts the other Decepticons, Starscream, Bonecrusher, Brawl, Barricade, and Blackout. Starscream attacks the dam and Frenzy frees Megatron from his frozen prison, where he joins his cohorts into pursuing Sam and the Autobots. Bumblebee shrinks the cube to a reasonable size so they can escape with it. They then arrive at Mission City, where a large battle ensues. Working together, the Autobots and human soldiers defeat Bonecrusher, Blackout, and Brawl. However, Bumblebee is crippled, and Jazz is killed by Megatron. When Megatron begins to gain the upper hand in the fight, Sam urges Optimus to put the AllSpark in his chest, which will destroy them both. Doing as he is told, Optimus pocesses the AllSpark like Twilight and her friends pocess the Elements of Harmony, a blue beam shoots out of the Cube and hits Megatron in the chest, which kills him and destroys the AllSpark. Before Optimus dies, he resquests for Thomas to take his place as the leader of the Primes and learns of Pitch and her dislikings of her Decepticon past. Thomas grants Optimus' request and he powers down.
In the aftermath, Optimus' body is dumped into the Laurentian Abyss in the Atlantic Ocean to be hidden, the government orders the closure of Sector 7, and the Witwicky family is released from custody. Sam and Mikaela soon start a new relationship, and Thomas says that the Autobots' fates have given them a new home, Earth, and sends a message calling out all surviving Autobots to join them. In a mid-credits scene, Starscream and Megatrain, an old enemy of OpThomas, escape into space, processing the events of the second movie.
