Captain Jean-Luc Picard awakens from a nightmare in which he relived his assimilation by the cybernetic Borg six years earlier (previously shown in the television episode "The Best of Both Worlds"). He is contacted by Admiral Hayes, who informs him of a new Borg attack against Earth. Picard's orders are for his ship, the USS Enterprise-E, to patrol the Neutral Zone in case of Romulan aggression, as Starfleet is worried that Picard is too emotionally involved with the Borg to join the fight. Learning the fleet is losing the battle, the Enterprise crew disobeys orders and heads for Earth, where a single Borg Cube ship holds its own against a group of Starfleet vessels. The Enterprise arrives in time to save the crew of the USS Defiant and its captain, the Klingon Worf. Picard takes control of the fleet and directs the surviving ships to concentrate their firepower on a seemingly unimportant point on the Borg ship. The Cube is destroyed after launching a smaller sphere ship towards the planet. The Enterprise pursues the sphere into a temporal vortex. As the sphere disappears, the Enterprise discovers Earth has been altered and is now populated entirely by Borg. Realizing the Borg have used time travel to change the past, the Enterprise follows the sphere through the vortex.
The Enterprise travels to April 4, 2063, the day before humanity's first encounter with alien life after Zefram Cochrane's historic warp drive flight; the crew realizes the Borg are trying to prevent first contact. After destroying the Borg sphere, an away team transports down to the site where Cochrane is building his ship, the Phoenix, in Montana. Picard has Cochrane's assistant Lily Sloane sent back to the Enterprise for medical attention. The Captain returns to the ship and leaves Commander William T. Riker on Earth to make sure the Phoenix's flight proceeds as planned. While in the future Cochrane is seen as a hero, the real man is reluctant to assume the role the Enterprise crew describe.
A group of Borg invade the Enterprise's lower decks and begin to assimilate its crew and modify the ship. Picard and a team attempt to reach engineering to disable the Borg with a corrosive gas, but are forced back; the android Data is captured in the melee. A frightened Sloane corners Picard with a weapon, but he gains her trust. The two escape the Borg-infested area of the ship by creating a diversion in the holodeck. Picard, Worf, and the ship's navigator, Lt. Hawk, travel outside the ship in space suits to stop the Borg from calling reinforcements by using the deflector dish. They destroy the disc but Hawk is assimilated. As the Borg continue to assimilate more decks, Worf suggests destroying the ship, but Picard angrily calls him a coward and vows to continue the fight. Sloane confronts the captain and makes him realize he is acting irrationally due to his desire for revenge. Chastened, Picard relents and orders the activation of the ship's self-destruct mechanism. While the crew head for escape pods, the Captain decides to stay behind and rescue his friend Data.
As Cochrane, Riker, and engineer Geordi La Forge prepare to activate the warp drive on the Phoenix, Picard discovers that the Borg Queen has grafted human skin onto Data, and with it an array of new sensations. She has presented this modification as a gift to the android, hoping to obtain the android's encryption codes to the Enterprise computer. Although Picard offers himself to the Borg in exchange for Data's freedom, Data refuses to leave. He deactivates the self-destruct sequence and fires torpedoes at the Phoenix. At the last moment the torpedoes miss, and the Queen realizes Data betrayed her. The android ruptures a coolant tank, and the corrosive vapor eats away the biological components of the Borg. With the Borg threat neutralized, Cochrane completes his warp flight. The next day the crew watches from a distance as an alien Vulcan ship, attracted by the Phoenix warp test, lands on Earth. Cochrane and Sloane greet the aliens. Having ensured the correction of the timeline, the Enterprise crew slip away and return to the 24th century.