Ship in a Bottle

Data is playing Sherlock Holmes on the Holodeck, a glitch appears and Lt. Barclay is called to investigate and he discovers protected Holodeck files. Professor Moriarty is then released and demands to see Captain Picard. Against the laws of physics, Moriarty is able to leave the Holodeck and takes control of the Enterprise.