The Enterprise is recalled to Earth on a priority mission pertaining to evidence of aliens on the planet 500 years ago. They are shown a cavern near Starfleet Headquarters in San Francisco containing relics of the 19th century, and Data's severed head. The Enterprise crew finds evidence pointing to a race of shapeshifters and cellular fossils native to the planet of Devidia II. Taking Data's head, the Enterprise travels to the planet, and discover a temporal disturbance on the planet. While there are no beings visible, Troi senses the presence of suffering humans, and the crew realizes that the aliens are slightly out of phase with time. Data notes that his android body has a phase discriminator that would allow him to see the aliens, and Captain Picard reluctantly allows him to do so. Data, once in phase with the aliens, describes them to the crew as absorbing strands of light from a device in the center of the cavern but otherwise appear benign. However, as he observes, two aliens enter a time portal that he is drawn into; Data finds himself on Earth in San Francisco in the 19th century.
Data quickly recognizes he needs money to operate, and is able to win a sizable amount beating card sharks at their own game in poker. Taking residence in a local hotel, Data claims to be an inventor, befriending the bell hop (who is in fact Jack London) to help in acquiring parts that will help him build a detector to find the aliens. Data recognizes Guinan, a long-lived El-Aurian, in a newspaper photo, and attends a reception that she will be at. As she is speaking with Samuel Clemens (better known by his pen name, Mark Twain), Data tries to ask her questions about the future believing her to have followed him back in time, but realizes that she has yet to meet the Enterprise crew; Data's language intrigues Clemens and he begins to follow Data and Guinan around.
Meanwhile, the Enterprise crew has determined how to build a similar phase discriminator to allow them to also see the aliens and go back in time to rescue Data. Guinan urges Picard to go along with the away team as, otherwise, they will have never met in the past and could change history. Picard and the rest of the away team activate the phase discriminator and see the same aliens as Data described, but discover that the strands of light they are consuming are human life forces, taken at the moment of death. The away team uses the time portal to travel back to the past to put a stop to the aliens.