With three days left to wait for a rendezvous, Geordi invites Data to play Sherlock Holmes to his John Watson in the holodeck. Both enjoy the trappings of their respective roles, but Geordi is quickly nonplussed when Data solves the Holmes mystery effortlessly, due to having read and memorized it. In Ten-Forward, Geordi tries to explain to Data that the fun is in trying to solve the mystery, but doesn't seem to be getting through. When Pulaski adds her two cents, and claims that human understanding of that type is beyond Data, Geordi suggests programming the computer to create an original Holmes mystery, and Data invites Pulaski along.

Unfortunately, this second attempt is merely a combination of elements from two different Conan Doyle stories, and fails as miserably as the first. Geordi tells the computer to create an adversary capable of defeating Data, and on the bridge, Worf suddenly detects a power surge. As the three continue wandering the streets of "London", Professor Moriarty appears, and miraculously, calls up the computer arch himself. Shortly afterward, Geordi and Data hear Pulaski scream, and Data quickly deduces Pulaski has been abducted.

Their first attempt to find her leads them to a dead end. When the Inspector gives "Holmes" a mystery to solve, Data quickly does so, but says it does not connect with their search, leading Geordi to conclude that the computer is running an independent program. They find Moriarty, who worries them with his talk of Data being "Holmes-yet not Holmes", and then shocks them by calling for the arch. He gives Data a picture of the Enterprise, and Data and Geordi leave in a panic. They try to shut down the holodeck, but cannot. Apparently, Geordi's instruction to create an adversary worthy of Data, and not Holmes, set up a chain reaction that gives Moriarty both power and consciousness. After examining alternatives, Picard decides the safest approach is for him, with Data, to go back into the holodeck and confront Moriarty.

By the time they reach him, Moriarty has gained a reasonable understanding of the ship's operations, and proves to them that he can cause damage by shaking the ship. Data, attempting to make the program run its course, concedes defeat, but Moriarty does not vanish. He claims to no longer be Moriarty, and says he wants merely to continue to exist...outside the holodeck. Picard sympathizes, as "Moriarty" is no longer evil, but cannot help. Moriarty, admitting failure, cancels the override protocol he'd placed on the holodeck. Picard suggests to Moriarty that they save his program until they find a way to recreate him more permanently. Moriarty is saved, and the Enterprise rendezvouses with the Victory.