The discovery of Data's head, old, dusty and dead, among the ruins of some 19th-century artifacts in San Francisco has led the crew on a wild-goose chase through time. In the 24th century, they have found a race on the planet Devidia II who can travel through time and assume human form on Earth. Meanwhile, Data has become trapped in 19th century San Francisco with a 19th century Guinan and a very curious Samuel Clemens.
Hoping to save Data's life, Picard, Riker, Beverly, Troi and Geordi transport to 19th-century San Francisco to find him. In a local morgue, Riker and Beverly realize that the aliens from Devidia II, disguised as humans, are slowly killing off the population by stealing their neural energy and sending it to the 24th century to feed their own people. Meanwhile, Samuel Clemens is following Data and Guinan, believing that they have somehow come from the future with a plan to destroy Earth.
At a local infirmary, the Away Team, in 19th-century garb, discover the two aliens from Devidia II, who have disguised themselves as a doctor and a nurse in order to steal neural energy from cholera patients. Beverly is able to snatch the "doctor's" cane, which is actually the device he uses to manipulate time. After a fracas, the entire group runs out just as Data arrives in a horse-drawn carriage to whisk them away to safety.
The group concludes that the cavern where Data's head was found somehow acts as a focusing device that enables the aliens to travel back and forth through time. Together with Guinan, they go back to the cavern, followed by Clemens, who has learned of their plan. After Clemens enters, the aliens themselves arrive, snatching back the cane and activating the process that allows them to time-travel. A sonic boom throws Guinan against a wall and separates Data's head from his body, which disappears into a hole of white light. The alien nurse is wounded, but the alien doctor dives into the hole, followed by Riker, Geordi, Troi, Beverly and Clemens. Picard stays behind with the injured Guinan, trapped in the 19th century.
The rest of the group, including Clemens and Data's body, lands on Devidia II in the 24th century, and safely transports back to the Enterprise. Troi tries to convince Clemens that mankind's future is assured, while Geordi works to successfully attach Data's 19th century head to his body. The crew is ready to destroy the alien habitat on Devidia II, but must rescue Picard from the cavern before they lose the ability to move through time. The author transports down and alerts Picard, who bids the 19th-century Guinan farewell and escapes just as the Enterprise's photon torpedoes destroy the alien planet.