The Starship Enterprise enters the Neutral Zone in response to a desperate plea for aid from the U.S.S. Yamato, which has been crippled by a series of dangerous, inexplicable malfunctions on its voyage to the homeland of the Iconians, an extinct civilization.

When the U.S.S. Yamato's captain tries to explain his mission to Picard, the transmission breaks up and the Yamato suddenly explodes. Investigating the incident, Picard learns that a mysterious probe was launched at the starship several days earlier, emitting a burst of energy at the ship. En route to Iconia to retrace the Yamato's course, the U.S.S. Enterprise experiences system failures similar to those the doomed vessel faced prior to its destruction. La Forge informs Picard that the probe rewrote the Yamato software, causing the antimatter containment failure that destroyed the ship, and that the Enterprise computer was infected when it downloaded the Yamato log prior to the explosion.

In an effort to save the Enterprise, Picard, Data and Worf beam down to Iconia. At the same time, a Romulan vessel orders the Enterprise to leave the Neutral Zone and begins to fire photon torpedoes at the ship, whose malfunctioning shields cannot be raised. Fortunately, the Romulan weapons suddenly disarm — it becomes clear that their ship is also "infected" because of their clandestine monitoring of the infected data from the Yamato. When Riker is finally able to activate the Enterprise's shields, he orders that they be kept up to deflect another Romulan attack — even though it will prevent the away team from being beamed back aboard.

Meanwhile on the surface, the away team accidentally activates an Iconian "gateway" which allows for immediate transport to distant places, such as other planets as well as both the Enterprise and the Romulan ship. When the power source which has been activating the probes attacks Data and tries to rewrite his software, Worf saves him by taking him back to the Enterprise through the gateway, while Picard stays behind to destroy the Iconian outpost to keep it from falling into Romulan hands. Geordi is unable to help Data, and the android appears to die. But then he awakes, a self-correcting mechanism having purged the memory infected by the foreign program. This gives Geordi the idea to wipe all memory from the ship's computer since downloading the Yamato logs. After Picard sets the outpost to destroy itself, he steps through the gateway and ends up on the malfunctioning Romulan ship, which is on a self-destruct sequence that its crew can't stop. By now the Enterprise systems have been restored and Picard is beamed safely back. Commander Riker informs the Romulans how to save their ship, and the Enterprise quickly retreats from the Neutral Zone.