Data experiences a strange dream that begins with him walking a corridor within Enterprise, then hearing a rotary dial phone sound, and sees three workmen that he says are "dismantling a warp plasma conduit". When he tries to speak to them, he can only emit a high-pitched noise. The workmen turn and rip off Data's appendages, finally tearing off his head, before Data "wakes" from the dream. Though Data is worried about the odd nature of dreams Counselor Troi suggests he continue, as dreaming can be therapeutic.
Captain Picard is invited to a regal Admirals' dinner, an event that Picard has been trying to avoid for several years as it would be rather boring. Unable to provide excuses, he orders the Enterprise towards Starbase 219 where the banquet is to be held, but they find the new warp drive will not engage. Data and Chief Engineer La Forge attempt to diagnose the problem, but after double checking the new configuration, the engines refuse to engage.
Later, Data finds himself in another dream, now set in Ten-Forward. In addition to the workmen, other members of the crew are present, in particular Troi as part of a large cake. The workmen prompt Data to cut into the shoulder of the cake while Troi tries to convince Data to stop. Suddenly Data "wakes," finding other crew members looking for him, as he has been late for his shift. Data has never experienced this before, and tries to understand the meaning of his dreams with a holodeck simulation Sigmund Freud. Later, while still working with La Forge to repair the engines, he begins to see imagery from his dreams while waking, including seeing crewmen with small mouths on their bodies, and an engineering tool appearing briefly as the cake knife. Later, Data attacks Troi on the turbolift, wounding her on her shoulder, where he claimed he saw one of those mouths. Data willingly puts himself under guard in his quarters, fearing what harm he might do to others.
Dr. Crusher takes care of Troi's wound but finds the spot still discolored after her treatment. Investigating further, she discovers the presence of interphasic creatures that are feeding on the Enterprise crew, which can only be seen under interphasic radiation. The crew realizes the creatures are where Data has been seeing the small mouths, and believes Data may know how to deal with the creatures through the dreams he has been experiencing. They hook up Data to the holodeck and watch as Data's dreams play out, helping Data to understand them. Data realizes that his mind has been telling him that he can adjust his circuitry to an interphasic pulse that will kill the creatures. After using the pulse, La Forge postulates that the new warp drive was infected with the creatures, and after confirming that they've been exterminated, is able to successfully engage warp, though the repairs take long enough that Picard is able to avoid the Admirals' dinner yet again.
Troi later visits Data, who has since apologized for his attack. Troi shows no resentment, but jokingly offers a bit of revenge: a cake shaped like Data for them to share.