Sixty-five million years ago, a race of aliens begin wiping out most life on Earth. Herds of brachiosaurids and hadrosaurs panicked trying to run as fast as they can from the cyberformed energy but did not escape in time. In the present, somewhere in the Arctic, a geologist named Darcy Tirrel discovers Tyrannosaurus and Spinosaurus. corpses covered in a strange metal.
Five years after the Battle of Chicago, humanity has grown wary and fearful of the Transformers. Cemetery Wind, an elite CIA black ops unit was formed by paranoid agent Harold Attinger and team leader James Savoy, has been assigned to hunt down the remaining Decepticons, but have also been secretly in hunting down the Autobots, believing them all to be a threat, despite the Autobots officially granted sanctuary by the government. With the aid of a Cybertronian bounty hunter Lockdown, they ambush and brutally kill Ratchet. However, their primary target is Optimus Prime, whom Lockdown personally wants alive.
In rural Texas, Cade Yeager, a struggling inventor, and his friend Lucas buy an old truck to strip it for parts to send Cade's daughter Tessa to college. Cade soon discovers that the truck is an injured Optimus Prime and repairs him after unexpectedly bringing him back to life. Locating Optimus in Texas, Cemetery Wind and Lockdown confront and threaten the Yeagers before Optimus rescues them and attacks the soldiers. Cade, Tessa and Lucas are saved by Tessa's secret boyfriend, Shane Dyson. After a long chase through the town, one of Lockdown's grenades instantly kills Lucas while the others escape. Tensions rise between Cade and the two teenagers over their secret relationship while Optimus rallies the remaining Autobots: Bumblebee, Hound, Drift, and Crosshairs. Cade hacks into a drone he took from the Texas attack, learning of KSI (Kinetic Solutions Incorporated), a robotic corporation, partnering with Cemetery Wind, and they decide to infiltrate KSI headquarters in Chicago, with Optimus vowing to kill Attinger for his crimes and actions against Autobots.
Meanwhile Joshua Joyce, the head of KSI, shows Darcy that he has perfected Transformium, the metal that the Transformers are composed of, but needs more. He has imprisoned Brains to decode dead Transformers' and utilize their data for human-created Transformers. Joshua shows Darcy his prized creation Galvatron, created using data from Megatron. The Autobots storm the facility, but Joshua stops them, proclaiming the Autobots are no longer needed now that they can create their own Transformers, and then Optimus and the Autobots decide to leave.
Forced by Attinger, Joshua launches Galvatron and Stinger (a man-made Transformer similar to Bumblebee) to pursue the Autobots. Optimus fights Galvatron before Lockdown wounds him, capturing him and Tessa on his ship. He explains that beings he calls the Creators want Optimus back. Before leaving Earth, Lockdown gives Cemetery Wind a Seed, giving the Autobots time to board the ship. Cade and Shane save Tessa and escape with Bumblebee while the others save Optimus and escape on a detachable ship. Optimus and Brains reveal that Galvatron is Megatron reborn and has manipulated KSI in order to steal the Seed and create more Decepticons. Cade warns Joshua, who retreated to Beijing to use production facilities there, about Galvatron and Attinger. Joshua backs off his deal with Attinger while Galvatron activates himself and infects all the KSI prototypes, turning them into the Decepticon army. Joshua flees with the Seed to Hong Kong, with Attinger chasing him.
When the Autobots try to retrieve the Seed, their ship is shot down by the Decepticons, leaving the Yeagers, Hound and Bumblebee to fight. After Cade kills Savoy in a fist fight, the Decepticons leave the Autobots outnumbered. Knowing this, Optimus releases and tames the legendary warriors known as the Dinobots. With their help, they defeat the Decepticons while Bumblebee kills Stinger at the battle's climax. However, Lockdown returns with a magnetic weapon to reclaim Optimus and the Dinobots. Optimus destroys it and fights Lockdown. Cade tries to help, but is held at gunpoint by Attinger, who is angered by Cade's choice to side with the Autobots. Optimus saves Cade by killing Attinger, but is immediately impaled by Lockdown with his sword to a wall. As Cade and Bumblebee holds off and distract Lockdown, Tessa and Shane use a tow truck to pull the sword out of Optimus, who then kills Lockdown. They finish off the remaining Decepticons as Galvatron retreats for parts unknown. Optimus sets the Dinobots free but decides to confront the Creators, knowing the Seed must be kept away from Earth. He requests the Autobots to protect Cade and his family before flying into space with the Seed, sending a message to the Creators that he is coming for them.
- Mark Wahlberg as Cade Yeager
- Nicola Peltz as Tessa Yeager
- Jack Reynor as Shane Dyson
- Kelsey Grammer as Harold Attinger
- Stanley Tucci as Joshua Joyce
- Sophia Myles as Darcy Tirrel
- T. J. Miller as Lucas Flannery
- Titus Welliver as James Savoy
- Li Bingbing as Su Yueming
- James Bachman as Gill Wembley
- Thomas Lennon as Chief of Staff
- Victoria Summer as Joshua's Executive Assistant
- Han Geng as Convertible Passenger
- Byron Li as Hong Kong police officer
- Austin Lin as Attinger's Driver
- Candice Zhao as Woman in Elevator
- Teresa Daley as Assistant to Minister of Defense
- Peter Cullen as Optimus Prime
- Mark Ryan as Bumblebee
- John Goodman as Hound
- John DiMaggio as Crosshairs
- Ken Watanabe as Drift
- Reno Wilson as Brains
- Robert Foxworth as Ratchet/Leadfoot