The Enterprise is in a binary star system with astrophysicist Paul Stubbs, who is preparing to test his theories with a burst of energy that the system releases once every 196 years. They prepare to launch Stubbs's "Egg", but then the ship suddenly shakes, shields go down, and the Enterprise is sent hurtling straight toward the accretion bridge between the giant and the pulsar.

They recover shields and engines in time to avoid all but minimal damage, but are perplexed when the computer claims there was no malfunction. Further confusion results when Beverly (returned from Starfleet Med), after fixing up Dr. Stubbs, finds a malfunctioning food dispenser. After reporting it, she talks to Picard about her concern that Wesley's almost too polite, and says he really should be getting into more trouble. Stubbs, friendly with Wesley, talks to him about fulfilling his potential, but then the sensors indicate a Borg ship approaching and the ship is put on full alert. The ship then vanishes, and all the computer can do is talk chess. Picard calls Riker and Data to his ready room to discuss the fate of this mission.

Stubbs intrudes on the meeting and objects strenuously to any suggestion of leaving, claiming he would rather die than leave. Wes, having nasty suspicions, checks his lab and realizes the problem is probably all his fault. He talks to Guinan about it, saying he accidentally let two Nanites (tiny robots designed to work in living cells) escape in tandem, and they may be responsible. After several more problems with the ship, Beverly confronts Wesley in his lab, hinting that perhaps he's taken on more than he can handle. Wes argues with her, saying "How can you know? You haven't even been here!", and the two decide to work together on the problem. They find the problem is worse than they thought: the Nanites are evolving, and are now working with a collective intelligence.

Stubbs, caring only for his experiment, tries to kill the Nanites with gamma radiation, but only manages to kill some, angering the Nanites, who then try to kill him later. Picard, grudgingly, agrees that the time has come to kill them all for the sake of the ship, but as he's about to, Data's attempts at communication succeed.

Data offers the Nanites his body as a conduit for face-to-face contact, and they accept. Stubbs apologizes for his actions, and throws himself on the mercy of the creatures. They agree to end the conflict, and say the ship has gotten too small for their needs. Picard relocates them to a nearby planet, and Stubbs's experiment goes as planned. Finally, Bev notices Wesley come into Ten-Forward with a girl while she talks to Guinan, and while happy to see him having fun for a change, immediately asks, "What do you know about this girl?"