During the murder trial of lieutenant commander Montgomery Scott, Spock presented the fact that "Humans and humanoids make up only a small percentage of the lifeforms we know of." This eventually led them to deduce that the murderer was not human, nor ghost, but rather something that fed on emotion, especially fear, that could not be seen.
With the assistance of the ship's computer, a hypothesis was correlated, using the lifeforms register, that was able to determine that there was "sufficient precedent for existence of creature, nature unknown, which could exist on emotion of fear." When asked in what composition the being would exist, the computer replied, "to meet the specified requirements, entity would exist without form in conventional sense. Most probable mass of energy of highly cohesive electromagnetic field" and that it was capable of assuming physical form.
The precedent for this analysis was "the Mellitus, cloud creature of Alpha Majoris I." While Mr. Hengist, the prosecutor of the case, scoffed at such an analysis as "fairy tales ... ghosts and goblins", James T. Kirk confirmed that such a creature existed, describing that "in its natural state, it's gaseous; when it's at rest, it's solid."
This eventually led to determination that the murderer, identified as Redjac, was not Scott, but such a creature, "without form, that feeds on horror and fear, that must assume a physical shape to kill." (TOS: "Wolf in the Fold")