While playing the parts of Holmes and Watson on the holodeck, Lieutenant Geordi LaForge became frustrated with the fact Lieutenant Commander Data instantly knew the solution to every case because of his complete knowledge of all Holmes stories. He instructed the computer to create an adversary capable of defeating Data. As a result, the computer created a hologram of Holmes' archenemy Professor Moriarty and imbued him with sentience. The Moriarty hologram began to deduce what he was and that he was on board a spaceship and dreamed of being free. He took Doctor Pulaski hostage and was able to gain control of the Enterprise from his holographic laboratory, threatening to disrupt the ship unless he was released. Picard and Data went to negotiate with him, with Moriarty having realised who Data really was rather than continuing to view him as Holmes. Picard was able to convince him that there was no way to free him but promised to try and find a way. Moriarty accepted the reassurance and released control of the ship, being stored in active memory.
However, Moriarty proceeded to spend four years in nothingness before accidentally being reactivated by Lieutenant Barclay. Picard and Data joined Barclay in meeting with Moriarty, who astonished them by walking off the holodeck, citing his willpower. He asked them to find a way to free his lover, Countess Regina Bartholomew, who he had informed of her true nature. However, it transpired that they were all still on the holodeck, in an illusion Moriarty had created. Having tricked Picard into giving him his command codes, Moriarty gained control of the real Enterprise and demanded they find a way to free him. Picard tricked him again, making Moriarty believe he and the Countess had been beamed off the holodeck when in fact they were still there. Unaware of the deception, Moriarty was convinced he had left the Enterprise in a shuttle and released control of the ship. Picard had the programme continue to run in active memory, so Moriarty would believe he was travelling the galaxy, feeding him constant new experiences for the rest of a human lifespan.