The Ux-Mal entities were those criminals from Ux-Mal exiled to the moon of 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.
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-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 T. 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 polar region 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 sought to transport their remains and taken for a proper burial on Earth. The phenomenon was recognized 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. (TNG: "Power Play")