"Sceptre of the Sun"
When the Enterprise is ensnared within the powerful grasp of a "genie", they find that they have become the pawns of an inter-stellar wizard. Later, as they discover what is behind his "magic", they suffer a devastating blow when they try to destroy his power base.