Ux-Mal entity

The Ux-Mal entities were those criminals from Ux-Mal exiled to the moon Mab-Bu VI. Their consciousness was separated from their bodies, and left adrift as anionic energy to suffer in the moon's intense electromagnetic storms. The entities could superimpose their neural pattern over corporeal species like humanoids and even androids.

History
The practice of exiling criminals to that moon occurred since the 19th century. By the 24th century "hundreds" of criminals were exiled on the moon.

When the USS Essex passed by Mab-Bu VI in 2167, the criminals attempted to escape by hijacking the crew's bodies, but the effort failed and the Essex crashed. However the Essex's distress call operated for centuries.

The signal was intercepted by the USS Enterprise (NCC-1701-D) in 2368, who attempted to identify its source. The criminal entities took over the minds of Data, Counselor Deanna Troi, and Chief Miles O'Brien. It was not possible to seize William Riker as he broke his arm, and his firing pain receptors made him immune to the takeover. On board the Enterprise, Troi, O'Brien and Data attempted to make the ship move to the southern pole of the moon, and when they failed, they hijacked the ship. They reached Ten Forward and managed to isolate it and use Captain Jean-Luc Picard, Worf, and Keiko O'Brien as hostages.

The trio claimed to be the spirits of the Essex crew, Bryce Shumar, Steven Mullen and Morgan Kelly and simply saught to transport their remains and taken for a proper burial. The phenomenon was recognised by Worf as the Klingon legend of jat'yln, but Picard was skeptical, as, despite the knowledge they displayed concerning the Essex and Starfleet vessels in general, their behavior was very incompatible with that of a Starfleet officer. Knowing that the entities did not like pain receptors, Dr. Beverly Crusher developed a plasma shock to release them from the host bodies, but the plan was foiled as the shock missed Data.

The entities in reality attempted to force the Enterprise crew to free their fellow prisoners by transporting them on board and then seize the bodies of the crew, but the attempt failed when Picard had the cargo bay locked down, threatening to vent it and kill everyone inside it to stop the escape. Knowing that both their hosts and their hostages would be willing to sacrifice themselves to save the ship, the criminals were forced to depart their borrowed bodies, returning to their imprisoned state. 

Background
Although the real individual names of the trio were not mentioned on screen, the production crew came up with nicknames for them during filming: Troi was Slash, Data was Buzz, and O'Brian was Slugger. (Captains' Logs: The Unauthorized Complete Trek Voyages)