After defeating Sentinel Prime and Megatron's army in Chicago, the Autobots have gone into hiding after the government deemed all transformers as threats, and thus, began to hunt them all down. The government has thus replaced the Autobots with their own transformers using technology from the fallen transformers. Meanwhile, a mechanic, his daughter, and his daughter's boyfriend become dragged into the conflict upon discovering Optimus Prime in their possession, and all the while, a mysterious new enemy, Lockdown, sets his eyes on earth.
In the three years since the Battle of Chicago, the Transformers have become outlaws. At the behest of CIA Agent Harold Attinger (Kelsey Grammer), a major campaign has been brought about to hunt down and destroy and and all Autobots or Decepticons that are still active.
Unknown to several different parties, Attinger is also working with an intergalactic bounty hunter named Lockdown (Mark Ryan). Working with a mercenary team known as The Cemetery Wind (led by James Savoy (Titus Welliver)), the group manages to find the Autobot Ratchet hiding in Mexico. After wounding the former Autobot medical officer, Lockdown demands to know where Optimus Prime is. When Ratchet refuses to tell, Lockdown rips Ratchet's 'spark' from his chest, and hands it over to Savoy and his team.
Meanwhile, in Paris, Texas, inventor Cade Yeager (Mark Wahlberg) and his partner Lucas Flannery (T.J. Miller) investigate an old movie theater for mechanical pieces they can probably salvage. While going through the dilapidated auditorium, Cade is amazed to find a flat-nosed semi truck hidden amongst the debris. Stranger still, the former theater's owner has no recollection of how it got there!
Cade purchases several of the theater's mechanical pieces intending to refurbish them, and the semi rig, intending to strip it down for parts. Needless to say, his daughter Tessa (Nicola Peltz) does not find his latest endeavor as anything more than her father shirking his responsibilities (their home is in danger of foreclosure, and Cade has been siphoning power from a neighbor). Cade still contends that his inventions and intentions will yield results, and help pay the way for Tessa to go to college.
While going over the semi-truck, Cade is surprised to find that the insides of the truck still activate, even though various mechanisms should have been damaged given its damaged state. When Cade hooks up a battery to the engine, and hears a booming voice say "Calling all Autobots," the inventor is sure he's found a Transformer!
Lucas claims that if they report the truck to the government, they could make $25-100,000 off of the find, which Tessa also backs up as a good idea (given that the money will pay off their debts, and give them some money she can use for going to college). However, Cade refuses, and instead wants to restore the truck, and investigate what makes it tick, confident that its alien technology can help him make his own creations work.
As he attempts to fix up the truck, it violently transforms before them all, into Optimus Prime (Peter Cullen). Optimus at first thinks that Cade and the others are there to hurt him, but Cade assures Optimus that he just wants to help. Optimus then tells how he was ambushed, and sent a message to the rest of his Autobot colleagues to hide, as an unknown party wants to hunt them down.
Things heat up when someone reports Cade's purchase of the semi truck, and soon, the Cemetary Wind are dispatched to Cade's property, where Savoy threatens to kill Tessa unless Cade gives them Optimus. Hearing Cade and his family is in danger, Optimus blows his cover, attempting to buy his human comrades some time to escape. In the firefight, Cade manages to grab a small drone that the Cemetary Wind guys are using.
Luckily, Tessa' (secret) boyfriend Shane Dyson (Jack Reynor) just happened to be coming by in his Rally Racer, and they pile in as Savoy and his men give chase. Optimus himself takes off, but is soon accousted by a grey Lamborghini, which is Lockdown! Both battles collide in the ruins of an old factory, where Shane's rally-racing skills help them take off most of the Cemetary Wind's crew. However, when the axle breaks, the group runs for it, but not before Lockdown unleashes a flash-metal weapon, that catches Lucas, encasing him in metal, as Cade, Tessa, and Shane jump into Optimus and drive away.
Optimus takes the humans to a dilapidated Gas Station, and drives off for bit, to make sure they haven't been followed. At the station, Cade is incensed that his daughter was seeing a boy behind his back (as he had forbid her to date anyone), though Shane and Tessa insist that they have known each other since high school. When Cade mentions Lucas' Irish accent, the young man mentions that he came to the states to Rally Race (and currently has Red Bull as a sponsor). However, given that his means of racing has been wrecked, he is willing to stick with Cade and Tessa, though mainly to take care of his girlfriend.
After the spat, Cade manages to use some technology in the old station, and hacks into the mini-drone he grabbed during the firefight. He is able to view the imagery it has recorded, including images that show the destruction of Autobots Ratchet, and Leadfoot, by the Cemetary Wind crew.
When Optimus Prime returns the next day, the group heads west towards Monument Valley, but not before stopping off at a small ATM. Using the drone, Cade attempts to have it use his ATM card, only to find that certain parties have locked his account. Needless to say, the transaction attempt is found out by Attinger, and a group of police cars quickly descend on the location looking for Cade, but the group is long gone.
As they near Monument Valley, Optimus scans a passing long-nose semi truck, and his exterior turns into a flashier, more modern semi rig, complete with red flames on a blue body. Pulling up into Monument Valley, several other Autobots emerge from hiding: Hound (John Goodman), Drift (Ken Watanabe), Crosshairs (John DiMaggio), and Bumblebee.
The other Autobots are wary of the humans Optimus has brought, but soften when their leader tells how they have helped him. Shortly afterwards, Cade shows the group the mini-drone's footage, and the other Autobots want to find out why they are being hunted. Cade also wishes to help them, to find out the people responsible for threatening his family.
Their investigation leads them to a company named KSI, located in Chicago, Illinois. KSI is headed by future-tech wunderkind Joshua Joyce (Stanley Tucci), who has been working with Chinese Entrepreneur Su Yueming (Bingbing Li) and Harold Attinger, to create man-made Transformers, to eventually be used for Military use.
Studying the remains of Megatron, Sentinel Prime, and numerous other pieces of alien hardware from after the Chicago war, the group has managed to synthesize a metal called "Transformium," which when given commands through a computer, can be manipulated into various shapes.
KSI has already made a drone based around Bumblebee's design, named Stinger, but Joyce's major project is an even bigger drone that he has named Galvatron. However, the attempts to make Galvatron to Joyce's standards has not worked, as all prototypes have been unable to form properly from the Transformium used, and the final robot design does not meet Joyce's request to make it resemble Optimus Prime.
With Bumblebee's help, Cade and Shane manage to have fake ID badges made, and Cade manages to infiltrate KSI. Using the mini-drone, Cade beams imagery back to the Autobots about what he is seeing, including a small Autobot named Brains (Reno Wilson), and the severed head of Ratchet, which is being melted down to obtain the Transformium material within him.
Unfortunately, the use of Cade's ID badge is found to be fake, and he is caught by security, and taken to see Attinger. Attinger tells Cade that what he has seen is a precaution, to make sure that the world will be safe, and demands to know where Optimus Prime is. However, Cade still refuses to talk.
The image of a fallen comrade's remains being mutilated sends Prime into a fury, and he leads the Autobots on a charge into KSI's facilities. Bee manages to rescue Cade from Attinger's office, and the group then breaks into the manufacturing floor, intending to destroy the works before Joshua Joyce appears. Joyce claims that what is being done is as a deterrent to any further Transformer damage, and claims that the humans "don't need" the Autobots anymore. The group does manage to free Brains from his captivity.
Optimus Prime then leads the others out of the factory, only for Attinger to then accost Joyce, claiming the Autobots have pretty much declared "open war" on the humans by breaking into the factory. Attinger is able to coerce Joyce into using Stinger and Galvatron to take down the Autobots. On a highway leading out of Chicago, the two human-controlled drones transform, and attempt to take down the Autobots.
Of the two, it is Galvatron who is sent after Optimus Prime, who attempts to stab Galvatron in his 'spark chamber,' but finds none. When Prime is surprised that his combatant doesn't have a spark, the human-made Transformer growls, "that is why I have no fear!"
Suddenly, a volley of shots knocks Optimus Prime to the ground, and Lockdown and his ship appear. As Galvatron then drives away, Lockdown glowers over Optimus Prime, telling him that his Creators "want him back." A net is then deployed, and Optimus Prime is hoisted up into Lockdown's ship, along with a nearby vehicle.
It happens that Tessa had sought refuge in the vehicle, and Cade attempts to get her out, but fails.
Lockdown then has Optimus Prime put in a cage, and Optimus Prime notes several other aliens in cages. He is also informed that the ship was originally used by a group of Legendary Knights, until Lockdown converted it into his prison ship. As the ship makes it's way over Chicago, Attinger is informed of Optimus Prime's capture, and arranges for Savoy to meet on Lockdown's ship. Though a number of government agencies want to fire on the ship, Attinger uses his clout to call a cease fire, claiming he has "an asset" on the ship.
As it flies low over a bridge, Cade, Shane, and the other Transformers clamber aboard. While the Autobots manage to rescue Optimus Prime, Cade and Shane find Tessa, who has seen Savoy take receipt of a silver object called "the Seed" from Lockdown, as part of the deal for capturing Optimus Prime. Cade and Shane also find their way into a strange weaponry, and Cade takes possession of a sword that opens into a laser gun.
To cause a distraction, Crosshairs has the ship's docking cables deploy, causing them to attach to The Willis Tower, and stop the ship from warping into space. This allows Cade, Shane, and Tessa to scale down onto the tower with Bumblebee's help.
Crosshairs soon appears in a gunship, and the group hope aboard, as several gunships from Lockdown's ship give chase.
Meanwhile, having finally detached the mooring cables, Lockdown prepares to go into warp, but Prime and the others find his prison cell is actually a detachable ship, and fly away before they can go into space, with Optimus Prime certain Lockdown will be far away before he finds out what has happened.
Back at KSI, it is decided that in order to continue operations, all the equipment will be moved to their Hong Kong facility. Joyce is also upset that control of Galvatron in the fight was lost at several points... let alone that the Transformer spoke (something it was not programmed to do)!
The Autobots and humans regroup near a train yard, where Optimus Prime says that during his fight with Galvatron, he sensed the presence of his old nemesis: Megatron. Brains then confirms this, as he was forced to decipher functionality still present in the Decepticon's brain, which helped formulate the building of Galvatron's body (and explains why Joshua Joyce could not get the system to make Galvatron resemble Optimus Prime). Galvatron also used his knowledge to allow Joyce to build Stinger and the other drones, with plans to turn them into Galvatron's new army.
Tessa soon explains about the seed she saw, and Optimus explains about how their creators used the seed, to wipe out species on planets, and harvest life-giving metal... the kind that created them, the Transformers!
Drift then intercepts a communications message containing information that Joyce is going to KSI's factory in China. After finding this out, Cade calls Joyce, and relays what they have learned regarding Galvatron. Knowing Joyce is also an inventor with a heart, Cade pleads with Joyce to deactivate Galvatron before things escalate.
As the police are arriving at the train yard, Cade, Tessa and Shane join the Autobots on the spaceship. But Optimus Prime states that the Autobots are going to Hong Kong to retrieve the Seed, but after that, they are done defending the humans. Cade voices out his disagreement over this to no response by Optimus Prime.
It is shown that Lockdown finally realizes that his captive had escaped from him, and the transformer insists to his pilot to reverse course and head back to Earth. Lockdown grumbles about Optimus Prime taking his 'trophy case' and that the Prime shall feel Lockdown's wrath for it.
Joyce then meets with Attinger and Savoy, who present him with the Seed. Joyce's plans are to detonate the seed in a region of the Mongolian desert, then harvest the results, which should give them enough Transformium to increase production for Military use. Attinger is eager for them to now ramp up production, but grows incensed when Joyce thinks they should slow down (obviously moved by Cade's premonition).
Meanwhile, on the factory floor, Galvatron suddenly activates, and begins to infect the other KSI-created Transformers (of which there are over 50!).
Joyce quickly has Attinger and Savoy shuffled out of the building when the alarm goes off regarding Galvatron. He then gets into a car with Yueming and an associated named Darcy (Sophia Myles), along with the seed.
As the three drive away, they soon decide they need to find a place to hide the seed. As dawn rises, Darcy drives off in their car to create a diversion, while Yueming attempts to help Joyce get the seed out of the city. During their escape, Joyce texts his scientists to find out the blast radius of the seed... and is told that it has the range of a thermo-nuclear device!
As Joyce takes refuge on a rooftop, the Autobots' ship approaches, and attempt to scoop up Joyce and the seed. However, Galvatron and his drones have appeared, and attempt to shoot down the ship. This causes the humans, Bumblebee, and Hound to spill out of the open gantry, as the ship spirals off into a mountainous area nearby, with Prime, Crosshairs, and Drift (along with the captured Legendary Knights aboard).
As Hound and Bumblebee attempt to fight off the drones, the Cade and the others attempt to get down from the roof, only to be fired on by Savoy nearby! Cade draws Savoy off, and the two have a chase across the rooftops, before a fight in a small apartment sends Savoy out a window to his death.
Attinger who has witnessed the death of Savoy, then receives a message from Lockdown. Attinger then confirms to Lockdown that Prime is nearby, and Lockdown begins his journey back to Earth.
Meanwhile, Hound and Bumblebee are greatly outnumbered by the drones, and radio their situation to their friends. Optimus then takes one of the swords from the ship, and frees the other Legendary Knights who were captured aboard the ship: aka, the Dinobots! Prime promises their freedom if they will help the Autobots. With that, the 4 released beings transform, and head towards the fight!
With their help, the Autobots manage to destroy the drones, but Galvatron escapes in the fight while Stinger is killed by Bumblebee. However, the mood is broken when Lockdown's ship appears, and begins to suck up anything metal! It almost ends up taking the seed and Optimus, before the Prime uses his weapons, disables its anti-gravity mechanism!
Prime then follows the ship to a silo on an island off of Hong Kong, where Lockdown descends, angered and ready to destroy the bounty that took his trophies!
Cade rushes off to help Optimus, but is accosted by Attinger, who is willing to kill Cade for disrupting his plans. However, in the fight nearby, Optimus notices Cade in danger, and fires on Attinger, killing him instantly! However, this move leaves Prime wide open, and Lockdown impales Optimus with his own sword!
Just when it looks like the end, Bumblebee returns, with Shane and Tessa, who use a nearby tow truck and its cable to help knock Lockdown off his feet, and pull the sword from Optimus' chest. Just as it seems Lockdown is about to dispatch Cade!, the help manages to allow Optimus to finally slice Lockdown in half, killing the villainous bounty hunter.
Optimus then uses Lockdown's grenade to destroy all the remaining KSI Drones, before escaping with the Yeagers and Shane, Galvatron realizes this and uses Lockdown's ship to flee, but before departing his last words are "We shall meet again Prime! For I am reborn!"
In the aftermath, Optimus tells the other Autobots and his human comrades who have helped him, that there is still someone looking for him. He intends to take the seed away from Earth, and possibly try to find out who sent Lockdown after him.
Using some rocket boosters in his feet, Optimus shoots out of the Atmosphere, and into space... intent to find his Creators.