Data and Geordi are enjoying a Sherlock Holmes holodeck mystery, when Data's suave reveal - involving the left-handedness of one of the suspects - is stopped in its tracks, as it turns out the suspect is apparently right-handed after all, even though according to this particular mystery, he was supposed to be left-handed. They stop the program and call Lieutenant Barclay in to check things out, who does a few diagnostics, then finds a locked program on the holodeck memory. When he asks it to run, who should appear but Professor Moriarty. It's been about four years since Data first granted him accidental sentience and he was subsequently left in the memory banks with a promise to find a way to free him. Unfortunately, he hasn't been "asleep" during that time as was intended; he has been trapped and aware of his surroundings (such as they were), waiting to get out and, as he puts it, slowly going mad. When Barclay tells him that he hasn't heard of Moriarty's situation and truthfully admits that there still isn't any technology to allow him to leave the holodeck, Moriarty gets angry and he demands to meet Picard, who'd made the promise to help him.
In the meantime, the ship is monitoring the impending birth of a new star, which will involve the collision of two gas giants. Picard is called down to the holodeck, and with Data and Barclay, he enters to talk to Moriarty. Picard is apologetic for both Moriarty's inadvertent imprisonment and the lack of progress in finding a way of allowing him to exist in the real world. Not only is Moriarty upset, but now he says that he can't trust Picard to work in his interest, and demands some sort of assistance to free himself from the Holodeck. Picard insists that it's impossible to get him out, and to demonstrate his point, he tosses a book through the open door, letting the simulated matter flash away into nothingness as it crosses the barrier. Moriarty claims that he is different, being alive, and that if he is just a computer simulation, it won't be a huge loss if he vanishes. So he steps beyond the door.
And he's just fine. He's out of the Holodeck, and doing just fine. The crew is understandably quite confused, and want to work to study how this was possible while Moriarty takes in the glory of the twenty-fourth century for the first time. Moriarty soon realizes that he's all alone in the future, though, and wants to to bring the Countess, a character written to be his love who he's truly fallen in love with on his own, into the real world with him. When he feels like the crew of the Enterprise isn't doing enough, he takes over the commands, demanding that they immediately devote their efforts to helping his love, or he'll let the ship drift into the star.
Barclay meets the charming Countess as they try their experiments with creating real matter from holodeck matter. The process is a failure, but Data hopes to learn something from the results, but when he looks at the results, nothing is there, as if they had never tried their experiment. Down in Engineering, LaForge tries to help Picard get back into control of the computer, but even after putting in his command override, it still won't respond. Data notices that Geordi is switching handedness, and explains to Picard that he now understands what has happened—when he, Picard and Barclay entered the holodeck for the first time, they never left afterward; the simulation was extended to include the ship, to think that they had returned. The lack of any results from their beaming experiment was because the real ship had no information on what would happen. And since they're still in the holodeck, now Moriarty has Picard's command codes. And he's locked them out of ending the program.
In real life, Moriarty contacts the bridge, having taken control of the ship, and demands that the crew start working on bringing them out of the holodeck for real—when Geordi and Riker sound like they don't think it'll work, he starts raising the temperature of the warp core until they agree to work on bringing him out into the actual real world. Picard goes to visit the Countess in the holodeck (within the holodeck that the simulated Enterprise is in) and asks her to talk to Moriarty about releasing the ship, appealing to her good nature, and offhandedly mentioning that they had found a way to Technobabble their way to transporting holodeck matter. The Countess tells Moriarty about said technobabble, and Moriarty relays it to the real Enterprise's Riker.
Reluctantly, Riker beams Moriarty and the Countess aboard the real Enterprise, where they arrive safely. Moriarty demands a shuttlecraft for he and the Countess to leave to explore the stars in, and it is given to them. As they fly out into space, Moriarty gives his command override code to the Enterprise. Then Picard steps out, tells the computer to end the program, and Riker disappears, along with the shuttle bay, returning to the grid of the holodeck.
Because, as is revealed, Picard had programmed a holodeck inside of the simulated Enterprise—so when Moriarty thought he was transporting out of the simulated Enterprise to escape to reality, he was in fact calling out to another holodeck program, nested inside his own. With the command codes from him, Picard and the others are able to free themselves, and emerge from the real holodeck. Barclay pops a clear glowing cube out of the holodeck's computer as they leave.
The Enterprise moves back to safety, and Moriarty and the Countess are held in the cube, which is simulating the galaxy for them. Barclay puts the cube into a power source which will keep them running to live out their lives exploring their simulated microcosm. Picard makes an offhand mention about how their own universe could be just an elaborate simulation for some unknown purpose, and once everyone else has left, Barclay nervously says, "Computer, end program." Nothing happens, and he looks relieved as he leaves to put Moriarty and the Countess somewhere safe.
As the credits start to play, we get a shot of the star-to-be they've been watching finally forming into a star in a big burst of red light.
Contains Examples of:
- A Glitch in the Matrix: Data realizes that the ship is a holodeck program because Geordi is left-handed in the program, but right-handed in real life. Amusingly, Barclay uses the trope name several years before the actual Trope Namer when he first began investigating the holodeck.
- And I Must Scream: Moriarty was aware of the passage of time while he was deactivated.Barclay: You couldn't have been aware of the passage of time Moriarty: But I was. Brief, terrifying periods of consciousness... disembodied, without substance.
- Artistic License: Moriarty refers to his past as a mere fiction, "the scribblings of an Englishman dead now for four centuries." However, Sir Arthur Conan Doyle was Scottish.
- Bittersweet Ending: Moriarty didn't get exactly what he wanted, but he's enjoying some semblance of life outside the holodeck with his love.
- The Bus Came Back: They wanted to bring Moriarty back earlier, but they had gotten in a bit of trouble with Sir Arthur Conan Doyle's estate; when they used Moriarty in "Elementary, Dear Data," they didn't realize he wasn't yet in the public domain. It took them a little while to get that straightened out.
- Chekhov's Gun: While playing Holmes in the beginning, Data and Geordi see that the holodeck is malfunctioning as a character is right-handed when he's supposed to be left-handed. Later, one of the ways Data realizes they're trapped in the holodeck is seeing that Geordi is apparently left-handed when in reality he's right-handed, using the same method: tossing an object in their direction.
- Deadpan Snarker: The Countess. Dont be fooled by her bright-eyed perkiness: the woman has some game.Picard: Ive come here to prevail upon your intelligence and your insight.Countess: But not, apparently, my humility.
- Hoist by His Own Petard: Picard used Moriarty's plan to turn the tables on him.
- Leaning on the Fourth Wall: "All this might just be an elaborate simulation running inside a little device sitting on someone's table." Said by Picard from inside your TV set, which you probably have sitting on some kind of table.
- Oh, Crap!: Picard, when he realizes that, in their attempt to override Moriarty's control of the computer, he's actually given him his access codes and allowed him to take control of the ship for real.
- Shout-Out: When Riker (the real one) demands to Moriarty that he gives back control, Moriarty tells him "I'm afraid I can't do that.".
- Spoiler Title: If you think about the episode title for a while, it's not hard to figure out Moriarty's plan before it's revealed.
- Spotting the Thread: Aside from the example above, a hint to the audience that all is not right is that from the time Picard, Data, and Barclay enter the holodeck to when Moriarty contacts the real Riker, there are no external shots of the Enterprise.
- This would actually become the standard for all Mind Screw episodes of Star Trek.
- Technobabble: Disabling the Heisenberg compensators has nothing to do with allowing Moriarty to leave the holodeck, it's just the crew's excuse as part of their counter-ruse. (Appropriately, the compensators themselves only exist to Hand Wave the transporter's physics-defying abilities. It runs on magic as far as the audience is concerned.)
- That Man Is Dead: Moriarty tells Picard that because of his self-awareness, he is no longer the literary foe of Sir Arthur Conan Doyle's creation.
- Title Drop: Moriarty describes what he created as a ship in a bottle for Picard, Data, and Barclay.
- Well-Intentioned Extremist: Moriarty.
- What Happened to the Mouse?: Invoked by Moriarty, who is understandably angry to discover he'd been forgotten about.
- The show always intended to revisit Moriarty, but unfortunately the issue of rights came up with the estate of Sir Arthur Conan Doyle, as the writers mistakenly thought Sherlock Holmes was in the public domain at the time. This episode came about because they were finally able to resolve that issue.
- What the Hell, Hero?: Moriarty criticizes Picard for having never kept his promise from the end of "Elementary, Dear Data".
- Worthy Opponent: Despite his frustrations, Moriarty has the utmost respect and admiration for Picard.