Star Trek: 25 Greatest Next Generation Episodes
11. Ship In A Bottle
Here's all the backstory you really need to know for this classic: four years ago, Geordi got royally pissed off at Data for spoiling every Sherlock Holmes adventure on the holodeck and got the computer to create an original adventure with a worthy adversary capable of defeating Data (and not Sherlock Holmes? Grammar saves, Geordi).
The computer, in one of the most metaphysically skewed plotholes conceivable, makes its representation of Professor Moriarty a sentient being that is aware of the Enterprise's existence and will stop at nothing to be able to leave the holodeck. Four years later, the Moriarty program has been sitting in encrypted storage until Barclay, who wasn't assigned to the Enterprise until a year after all of this happened, accidentally activates it, which has apparently remained self aware in computer storage for all these years.
When Picard is summoned to speak to him about leaving the holodeck, Moriarty amazingly does just that. Of course, no hologram can leave the holodeck without immediately disintegrating so naturally Data deduces that they are in fact still on the holodeck, leading to a resolution that quite frankly has given most Trekkies a headache the last twenty years. Even the cast had to keep diagrams on set to understand what was going on in the plot that would even give Steven Moffat a run for his money.