The film opens with Optimus Prime, heroic leader of the benevolent Autobots, describing in a voice-over the destruction of the Transformers' home world, Cybertron. It was destroyed by the evil Decepticon leader Megatron in his quest to obtain the All Spark. The Autobots want to find the All Spark so they can use it to rebuild Cybertron and end the war between the Autobots and the Decepticons, while the Decepticons want to use it to defeat the Autobots and conquer the universe. Megatron found the All Spark on Earth, but crash-landed in the Arctic Circle and was frozen in the ice. Captain Archibald Witwicky and his crew of explorers stumbled upon Megatron's body in 1897. Captain Witwicky accidentally activated Megatron's navigational system and his eye glasses were imprinted with the coordinates of the All Spark's location. Sector 7, a secret United States government organization founded by Herbert Hoover, discovered the All Spark 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.
In the present day, the group of Decepticons — Blackout, Scorponok, Frenzy, Barricade, Starscream, Devastator and Bonecrusher — have landed on Earth and assumed the disguise of Earth vehicles (except Scorponok, who hides within Blackout). Blackout and Scorponok attack the U.S. SOCCENT FWD military base in Qatar and try to hack into the U.S. military network to find the location of Megatron and the All Spark. Their mission is thwarted when the base staff severs the network cable connections. While Blackout destroys the rest of the base, Scorponok chases a small group of survivors who have photographic evidence of the robots, but he is eventually repelled. During this battle, the military discovers the only effective weapons against the Transformers' armor are high-heat sabot rounds.
After Blackout's failure, Frenzy infiltrates Air Force One to again hack into the military network, planting a virus. He finds the map imprinted on the Captain Witwicky's glasses. Witwicky's descendant Sam Witwicky intends to sell the glasses on eBay. Frenzy and Barricade begin tracking Sam's location. Autobot scout Bumblebee is also on Earth, disguised as a 1976 Chevrolet Camaro, and is bought by Sam while shopping for his first car. Bumblebee helps him woo his crush, Mikaela Banes. Bumblebee leaves at night to transmit a homing signal to the rest of the Autobots and Sam sees him in robot mode. Barricade confronts Sam and demands Archibald's spectacles, but Bumblebee rescues him and Mikaela. They leave to rendezvous with the rest of the Autobots — Optimus Prime, Jazz, Ironhide, and Ratchet — who have landed on Earth and taken the forms of Earth vehicles as well. Sam, Mikaela, and the Autobots return to Sam's home and obtain the glasses; however, agents from Sector 7 arrive and take Sam, Mikaela and Bumblebee into custody. Frenzy, now disguised as Mikaela's cellphone, secretly accompanies the group to Hoover Dam and releases Megatron from his frozen state. Locating the All Spark, Frenzy sends an alert to the other Decepticons. Sam convinces the Sector 7 agents to release Bumblebee so that he can deliver the All Spark to Optimus Prime. Frenzy's virus has shut down government communications, but a group of humans manage to establish a signal to the Air Force in order to support the Autobot-human convoy, who have gone to nearby Mission City to hide the All Spark. The Decepticons attack and Bonecrusher, Frenzy, Jazz, Devastator and Blackout are all killed during the ensuing battle. Sam, who was instructed to put the All Spark into Optimus Prime's chest (subsequently destroying it and Optimus Prime) if the battle went in Megatron's favor, instead chooses to ram the All Spark cube into Megatron's chest, destroying it and killing Megatron. Optimus takes a fragment of the All Spark from Megatron's corpse, but realizes that with its destruction, their home world Cybertron cannot be restored. Consequently, Optimus sends a signal to other surviving Autobots in the universe, directing them to their new home, Earth. The government orders the closure of Sector 7 and has the dead Decepticons dumped into the Laurentian Abyss. Starscream, who fled the battle, escapes into space.