The Ark spacecraft escapes Cybertron carrying an invention that could end the war between Autobots and Decepticons, and crash-lands on the dark side of Earth's Moon in 1962. NASA detects the crash, and President John F. Kennedy authorizes a mission to put a man on the Moon as a cover for investigating the spacecraft. In 1969, the crew of Apollo 11 lands on the Moon and secretly inspects the Ark before returning to Earth.
In the present day, three years after the battle of Egypt, the Autobots help humanity prevent major conflicts. During a mission to the site of the 1986 Chernobyl nuclear disaster to investigate suspected alien technology, the Autobots are attacked by Decepticon scientist Shockwave and his giant worm Driller. After the two escape, Optimus Prime discovers the technology is an Ark fuel cell. The Autobots travel to the Moon and find Sentinel Prime, the Autobots' leader before Optimus, in a comatose state along with five Pillars he created to establish a "Space Bridge", a wormhole that can teleport matter between two points. On Earth, Optimus uses the Matrix of Leadership's energy to revive Sentinel.
Meanwhile, Sam Witwicky lives with his new girlfriend, Carly Spencer, but cannot work with the Autobots. At his new job, co-worker Jerry Wang gives him information about the Ark before the Decepticon Laserbeak assassinates him. Sam contacts Seymour Simmons to investigate the Decepticons' murders of people connected to the American and Soviet lunar space missions. They locate two surviving cosmonauts, who show photos of hundreds of Pillars on the Moon, and realize that the Decepticons raided the Ark long before the Apollo 11 mission and left Sentinel and the five Pillars for the Autobots to find, knowing that Sentinel was the key to activating the Pillars. The Autobots rush to return Sentinel to their base for protection, but he betrays them and kills Ironhide, revealing that he made a deal with Megatron to ensure Cybertron's survival.
Sentinel uses the Pillars to transport hundreds of concealed Decepticons from the Moon to Earth. Dylan Gould, Carly's boss, is revealed to be working with the Decepticons and captures Carly with Soundwave, disguised as Carly's car. At the Decepticons' demand, the Autobots are exiled from Earth, but Starscream destroys their ship as it takes off. The Decepticons invade Chicago while placing Pillars around the world to begin transporting Cybertron to the Solar System, planning to enslave humanity and use Earth's resources to rebuild their homeworld. Sam teams up with former NEST soldier Robert Epps to go into Chicago to save Carly and arrest Dylan. The Decepticons nearly kill them before the Autobots, who anticipated the trap and survived their ship's destruction, intervene. Sam, along with NEST teams led by Lennox and Navy SEALs, rescue Carly and begin fighting the Decepticons. During the battle, the Decepticons execute the Autobot Que, and Bumblebee kills Soundwave, while Optimus fights Sentinel. Laserbeak, Starscream, Shockwave, and the Driller are also killed in the ensuing battle. Meanwhile, Wheelie and Brains sneak onboard and sabotage the Decepticon mothership.