Professor James Moriarty was a hologram created by Geordi La Forge, based on the fictional character of the same name. He was created for Sherlock Holmes Program 3A as an adversary capable of outwitting Data.
Moriarty's creation was unintentional and the direct result of a discussion between Data, La Forge, and Doctor Katherine Pulaski about Data's ability to solve problems like Sherlock Holmes would. Doctor Pulaski contended that Data could solve these problems because he had memorized all the Sherlock Holmes novels, but would not be able to solve a new Sherlock Holmes-based mystery. When La Forge suggested creating a mystery where Data's solving abilities could be tested, Pulaski told him Data would fail and agreed to take part in it. A short time after the mystery had begun, Data solved it with little effort, whereupon Pulaski accused Data of fraud, as she felt that it was not an original mystery but a variation on a theme. La Forge decided to let the computer create an opponent for Data, and told it to create an adversary with the ability to defeat Data. However, he said exactly that: an opponent intelligent enough to defeat Data, not Sherlock Holmes. After this command, a man in the background of the holoprogram seemed dazzled and watched as La Forge entered commands via the holodeck arch. This man was Professor James Moriarty.
Familiarizing himself with sentience
After Moriarty heard the commands used by La Forge, he addressed the arch himself and asked what it was. He was informed that it was used for entering computer commands. He wanted to know who the strange people were, and decided to follow them. After some time, Moriarty decided to abduct the woman of the group, Doctor Pulaski, and he hid her in a abandoned warehouse.
As time went by Moriarty became more aware of his own consciousness, seeing strange images inside his head that he could not name. Because clear signs were left behind when Doctor Pulaski was abducted, Moriarty was soon found by La Forge and Data. Moriarty welcomed them as Holmes and Watson, and also as not being Holmes and Watson. He told them they both looked familiar to him but then again also not familiar. He informed them that strange realities were part of his consciousness, and that he was aware of an oracle greater than Delphi's named "computer." After he summoned the arch, he gave a stunned Data a drawing he had made, a drawing of the Enterprise, and told them he knew it was a vessel of some kind and that he, and they, were aboard it. Data and La Forge immediately left the holodeck and took the image to Captain Jean-Luc Picard.
Meanwhile, Moriarty was courteous to the captive Doctor Pulaski, enjoying her company and discourse. He offered her tea and scones while he questioned her, and told her that he already knew who Picard was, although Pulaski said she had never heard of him. Moriarty showed her machinery he had built which he could use to control the Enterprise. He showed this same machinery to Picard, who entered the holoprogram with Data and La Forge. Moriarty told Data that this was about more than just ending a holodeck adventure, and he told Picard that he only wanted to exist. Moriarty made clear to Picard that he was well aware of his surroundings, and shook the Enterprise by means of his self-made machinery. When Moriarty asked Picard if he could leave the holodeck, Picard informed him of the limitations of the holodeck and that the matter and energy created by the holodeck could not exist outside of it.
Rights as a sentient being
Unpersuaded, Moriarty argued that he found himself alive, and as such had a right to live, to exist. He used Data as an argument – Data after all was a machine and yet considered alive, and he made the Cartesian argument, "I think, therefore I am." Picard told Moriarty that at this time they would not be able to give him what he wanted, because they did not know how to convert holodeck matter into a permanent form.
Moriarty continued to press his case and told Picard that he did not want to die, who replied that he did not want to kill him. After Moriarty said goodbye to Dr. Pulaski, he summoned the arch and returned the holodeck controls to the main computer, and put his fate in Captain Picard's hands. Moriarty knew the Enterprise had a vast library memory, and Picard told him that they would use it to save his program, and that they would continue to try to find a way for him to exist outside of the holodeck.
Return and leaving the holodeck
In 2369, four years after Moriarty's program was stored, Data and La Forge were again running a Sherlock Holmes holonovel, when they found some discrepancies and asked Lieutenant Reginald Barclay to check on the program and the holodeck. When Barclay found the protected memory, he unlocked it and ran the program it contained. Moriarty appeared and asked Barclay if Captain Picard was still in command of the Enterprise. A confused Barclay listened as Moriarty explained who and where he was, and asked Barclay if Picard had found a way to enable him to leave the holodeck. Barclay responded that Moriarty could still only exist inside the holodeck.
Surprisingly, it seemed that Moriarty was aware of the passing of time while he was stored in protected memory. Moriarty asked how long he had been away, remarking that it had seemed longer than four years and asked to speak with Captain Picard. When he was told by Barclay that he had to store him in memory again, Moriarty appeared to cooperate, but in fact remained active after Barclay left the holodeck.
Moriarty did not know if Picard would help him this time and devised a ruse. He met Picard in Holmes' room at 221B Baker Street. Moriarty did not believe Picard when told that he had not been forgotten and that Starfleet's finest scientists had not found a way to allow him to leave the holodeck. He told Picard that it was a matter of willpower, and when Picard summoned the holodeck exit, Moriarty walked through it before anyone realized what he had done. A stunned Picard and Data walked up to him and could not understand how this was possible. Moriarty was told by Picard that he needed to be examined and was taken to Doctor Beverly Crusher, who found nothing wrong with him and that other than unusual DNA, he was Human. (TNG: "Ship in a Bottle")
Help in bringing out the Countess
The newly-liberated Moriarty was given a tour of the Enterprise by Captain Picard and looked at the stars when they entered Ten Forward. When Picard expressed concerns about the criminal behavior his character was known for, Moriarty told him that this was all fictional and had nothing to do with real life. Moriarty asked Picard if the Countess Regina Bartholomew, the love of his life, could also be brought off of the holodeck like himself. Picard told the Professor that they did not understand why Moriarty could leave the holodeck and had no idea how to replicate the feat.
Despite Picard's assurances that Barclay and Data would investigate it the possibility of bringing the Countess off of the holodeck, Moriarty decided to force the issue and took control of the Enterprise. Unknown to Picard, Moriarty had already changed the command codes into his own so he could override every command entered. The situation was made more critical by the impending collision of two planets in the Detrian system, which the Enterprise had been monitoring.
After making his demands, Moriarty returned to Baker Street, where he found the Countess Bartholomew together with Barclay, who placed pattern enhancers around a chair to test whether they could use the transporter to beam something off of the holodeck into the real world. The attempt failed, but it gave Data the clue he needed to realize how Moriarty had left the holodeck; he had instead created a holographic representation of the ship, with Picard, Data and Barclay – the only people who had been in the holodeck when he created this illusion – real people.
Unaware of Picard's discovery of his deception, Moriarty contacted Commander Riker, who was stationed on the bridge, and asked about their progress in getting him off of the holodeck. When Riker replied that they had made no progress, Moriarty informed them of the experiment with the transporter and reminded Riker that he had nothing to lose by allowing the Enterprise to be destroyed by the planetary collision.
When Moriarty returned to Baker Street, he was informed by the Countess Bartholomew that Picard had told her that it might be possible to bring them off the holodeck by un-coupling the Heisenberg compensators before transport. Moriarty asked her if she had heard it correctly, and when she confirmed it he grinned. She told him that before Picard would try this, however, he wanted control of his ship back. Moriarty summoned the arch and told Commander Riker about Picard's plan.
Moriarty and the Countess Bartholomew stood between activated pattern enhancers to be beamed off the holodeck. After the transport, they met Commander Riker, and Moriarty told him that he would only return the command codes when he and the Countess were off the Enterprise, and he demanded a shuttle. Riker reluctantly agreed.
Moriarty entered the shuttle together with his beloved Countess, and Riker suggested they head for Meles II, as the range of the shuttle was not unlimited. When the shuttle departed the Enterprise shuttlebay, Moriarty released the command codes to the Enterprise main computer. When the Countess asked him if one day they would return to Earth he assured her they would.
Unknown to Moriarty, Data and Picard had created a program within the program, allowing Moriarty to believe he had departed the holodeck despite actually remaining within it. Picard and Data then ended the program the moment the command lockouts were removed, and left the holodeck a few minutes later. Moriarty and the Countess Regina Bartholomew would spend the rest of their lives inside a memory module, unaware of their situation, for as far as they were concerned they had left the Enterprise to live their lives in the real world. (TNG: "Ship in a Bottle")
Effect of Moriarty
After the first encounter with Moriarty, the Enterprise-D turned its findings over to Starfleet's most experienced theoretical scientists. Moriarty, however, didn't become public knowledge at that time, even to Enterprise engineers. (TNG: "Ship in a Bottle")
The events surrounding Moriarty's re-emergence were ultimately taught at Starfleet Academy. Before his graduation in 2370, Harry Kim was one of the Academy cadets to learn of Moriarty. (VOY: "Alter Ego")
Moriarty's history would be covered under the Starfleet database and included on all starships. In 2373, Chakotay looked up the information on the USS Voyager's database when investigating the possibility of another sentient holodeck character (although the character was later revealed to have come under the control of an outside intelligence rather than having become sentient herself). (VOY: "Alter Ego")
"It has described a great monstrous shape on which I am like a fly – stuck on a turtle's back – adrift in a great emptiness."
- - Moriarty, on his perception of the Enterprise and his place on it
"I think, therefore I am"
- - Moriarty, shortly after leaving the holodeck
"You – or someone – asked your computer to program a nefarious fictional character from nineteenth century London – and that is how I arrived... but I am no longer that creation. I am no longer that evil character, I have changed. I am alive – I am aware of my own consciousness."
- - Moriarty, on his evolution