In the 24th century, Captain Jean Luc Picard awakens from a nightmare in which he relived his assimilation by the cybernetic Borg six years earlier. He is contacted by Admiral Hayes, who informs him of a new Borg threat against Earth. Picard's orders are for his ship, USS Enterprise, to patrol the Neutral Zone in case of Romulan aggression; 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. Enterprise arrives in time to assist the crew of USS Defiant and its captain, the Klingon Worf. After Admiral Hayes is killed, 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. Enterprise pursues the sphere into a temporal vortex. As the sphere disappears, Enterprise discovers Earth has been altered – it is now populated entirely by Borg. Realizing the Borg have used time travel to change the past, Enterprise follows the sphere through the vortex.
Enterprise arrives hundreds of years in its past on 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 Cochrane's ship, Phoenix, in Montana. Picard has Cochrane's assistant Lily Sloane sent back to Enterprise for medical attention. The captain returns to the ship and leaves Commander William T. Riker on Earth to make sure 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 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, Lieutenant Hawk, travel outside the ship in space suits to stop the Borg from calling reinforcements by using the deflector dish. As the Borg continue to assimilate more decks, Worf suggests destroying the ship, but Picard angrily calls him a coward. Sloane confronts the captain and makes him realize he is acting irrationally. Picard orders an activation of the ship's self-destruct, then orders the crew to head for the escape pods while he stays behind to rescue Data.
As Cochrane, Riker, and engineer Geordi La Forge prepare to activate the warp drive on Phoenix, Picard discovers that the Borg Queen has grafted human skin onto Data, giving him the sensation of touch he has long desired so that she can 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 and fires torpedoes at 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.