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 malevolent Decepticon leader Megatron in his quest to get hold of 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 obliterate the Autobots and take over the universe. Megatron had managed to locate the All Spark 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 eye glasses were imprinted with the coordinates of the All Spark's location, an incident that left him blind and mentally unstable. Sector 7, a secret government organization founded by President 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, 2007, the group of Decepticons named Blackout, Scorponok, Frenzy, Barricade, Starscream, Brawl and Bonecrusher, have landed on Earth and assumed the disguise of Earth vehicles. Blackout and Scorponok attack the U.S. SOCCENT forward operations 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 cuts the network cable connections. While Blackout destroys the rest of the base, Scorponok pursues a small group of survivors, led by Captain William Lennox and Sergeant Robert Epps, who have photographic evidence of the robots. Scorponok is eventually repelled and hides in the sand after the humans damage his tail. During this battle, the military discovers the only effective weapons against the Decepticons' armor are high-heat sabot rounds.
After Blackout's failure, Frenzy infiltrates Air Force One to again hack into the military network, planting a computer virus. He finds the map imprinted on Captain Witwicky's glasses. While the Pentagon interferes with Frenzy's plan, he finds that Witwicky's descendant Sam Witwicky intends to sell the glasses on eBay. Frenzy and Barricade begin tracking Sam's location. Meanwhile, Sam buys the Autobot scout Bumblebee (also on Earth disguised as a 1976 Chevrolet Camaro) as his first car. After Bumblebee helps Sam woo his crush, Mikaela Banes, he leaves at night to transmit a homing signal to the rest of the Autobots. Sam pursues Bumblebee, thinking someone is stealing his car, but is shocked to find his car is actually a giant robot, which he regards as evil as first. Sam then gets arrested, and in the police station, tries to explain to the police officer what happened, but the apathetic and impassive officer just assumes he's on drugs. When Bumblebee (in car mode) returns the following day, Sam flees, believing the car is stalking him. While out, Barricade attacks Sam and ferociously interrogates him about his grandfather's glasses. Bumblebee saves Sam and Mikaela and engages Barricade in battle. During the fight, Mikaela severs Frenzy's head but he transforms into her cellphone and hides in her purse. They leave to meet with the rest of the Autobot team — 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 and Mikaela into custody. The Autobots intervene, but Sector 7 captures Bumblebee and sends Sam and Mikaela away.
Sam and Mikaela are taken to Hoover Dam, as are Lennox and Epps, under Defense Secretary John Keller's orders. Frenzy sends an alert to the other Decepticons and sneaks into the technology system, freeing Megatron from his frozen state. Sam convinces the Sector 7 agents to release Bumblebee so that he can deliver the All Spark to Optimus Prime. Frenzy's hacking has shut down government communications, but Keller and two hackers, Maggie and Glen, manage to establish a signal to the Air Force in order to support the Autobot-human convoy that has gone to nearby Mission City to hide the All Spark. The Decepticons attack; Bonecrusher, Frenzy, Jazz, Brawl 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 favor of Megatron), instead chooses to ram the All Spark cube into Megatron's chest. The All Spark disintegrates, and its power obliterates Megatron. Optimus takes a fragment of the All Spark from Megatron's corpse, but admits that with its destruction, their home world Cybertron cannot be restored. The government orders the closure of Sector 7 and has the destroyed Decepticons dumped into the Laurentian Abyss. Lennox and Epps are reunited with their families, and Sam and Mikaela form a relationship. Optimus transmits a message to all surviving Autobots in space, telling them that they have a new home on Earth.
During the credits, Starscream, the only Decepticon to survive the battle, escapes into space.