Lieutenant Commander Data is once again working on his acting, portraying Prospero from Shakespeare's play "The Tempest" on the holodeck. Without warning a train, the Orient Express from another program, roars through the holodeck.
Elsewhere on the ship, a planetary survey is in progress, and Captain Picard gives the order to move to the next sector when the Enterprise suddenly goes into warp. Just as suddenly, the engines stop by themselves.
Geordi La Forge discovers a theta flux distortion had been building up on the ship, and concludes that had the Enterprise not gone into warp precisely when it did, the ship would have been destroyed.
Data theorizes that the Enterprise sensors picked up the distortion and triggered a safety feature, one that is not known to have been part of the ship's design. Investigating some, Geordi and Data discover a strange node that now interconnects many Enterprise systems, including the sensors and propulsion. Searching more, they discover nodes like it all over the Enterprise, all protected by small force fields.
Suspecting sabotage, Commander Riker, Data and Worf head to the holodeck where many of the nodes converge, to try to disconnect them. They discover the holodeck is activated, and when they enter, and find themselves on board the Orient Express, along with characters from other programs.
Data tries to access the holodeck systems to turn the program off, but is stopped by the train conductor. The conductor tells Data to go up to the train's engine, and when the engineer protests, a gangster holodeck character shoots him in the back. The conductor then pulls a cord, and suddenly the Enterprise again jumps into warp.
Leaving the holodeck, Data discovers the nodes have multiplied and are now connecting most of the ship's systems, with the exception of the main computer. He also observes structure of the nodes resembles a primitive brain, and concludes the Enterprise is forming its own intelligence. Since the key to understanding it seems to be in the holodeck, Counselor Troi goes in to gather information, with Data and Worf in tow.
Troi talks to the gangster, who is holding a brick he took from the engineer. He tells her that he has to get the brick to Keystone City, and when he gets off at that stop Troi and Worf follow him. Data tries to access the holodeck circuitry through a manhole, using his android strength to fend off a taxicab which is tasked with protecting the circuits.
The gangster proceeds to a brick wall with one brick missing, and puts the brick in. At that moment, a power surge kicks in a cargo bay - and when Geordi goes to investigate, he finds an object there in the process of being formed, atom by atom. Data attempts to depolarize the circuits under the manhole, but when he does the ship and holodeck begin shaking violently and Data has to stop.
The three leave the holodeck and meet the rest of the crew, and Troi explains that the programs running in the holodeck are acting out metaphors of creation. Picard suggests playing the holodeck scenario through to see where it leads. Data, Worf, and Troi return to the holodeck train, and this time tell the conductor they are headed to Vertiform City, which they had learned was the train's eventual destination.
The Enterprise arrives at a white dwarf star and begins automatically extracting vertion particles from it. The strange object in the bay begins growing very quickly and becoming more complex, becoming some kind of lifeform. But, when the star runs out of vertions, the lifeform has difficulty maintaining its energy, and the holodeck characters have a shocked response. The conductor pulls on the emergency brake, derailing the train, but causing a shipwide power shutdown across the Enterprise.
Geordi tells Picard that without more vertions soon, the lifeform being created on the holodeck will die. The train heads to New Vertiform City, and the Enterprise jumps to Warp 9. The Enterprise diverts power from life support to propulsion, which will begin to affect the crew within two hours.
Data convinces the conductor that he knows a shorter route to New Vertiform City, and gains access to the engine. He brings the ship to a nearby nebula, and Geordi gets the nebula to produce huge amounts of vertirons using a modified torpedo. The train passengers celebrate their arrival at the end of the line and then the program ends. The nodes deactivate all over the ship and the new lifeform, finally complete, rises in the cargo bay and leaves the Enterprise.
With all systems now restored, Data and Picard discuss the incident and speculate about the entity that had been born from the Enterprise. Data queries how Picard could have been confident that the emergent creature would not be dangerous. Picard states he believes the new lifeform will be benign, since its psyche arose not only from the ship's systems but from the crew's personal journals, mission logs, and other such sources; believing that the crew's experiences with the Enterprise have been honourable, Picard trusts that "the sum of those experiences will be the same".