The U.S.S. Enterprise tracks a mysterious SOS to an ancient planet presumed long dead. The crew hears a voice from a telepathic being named Sargon, who asks Kirk to beam down to the surface. When Kirk, Spock and McCoy arrive in the transporter room, they find that Dr. Ann Mulhall has also been summoned. Sargon operates the transporter and leaves the security guards behind.
The landing party find themselves in a vault, and encounter a glowing sphere that identifies itself as Sargon. He explains that his people were destroyed in a cataclysmic war half a million years ago, and that he once had a body, but now is only pure thought. Sargon insists that he and two others of his kind need to "borrow" the bodies of the Enterprise officers long enough to construct new artificial ones. Sargon briefly takes control of Kirk's body, and leads the landing party into another chamber holding two rows of spheres, which are all now dark except for two. Those two beings are Sargon's wife, Thalassa, and his former enemy, Henoch. Sargon explains that this is how they stored their minds after the war, laying in wait for someone to find them. But by now Kirk's body is weakening, so Sargon returns control to the captain.
Scotty beams the three receptacles aboard and McCoy monitors the transfer process in Sickbay. Sargon takes Kirk's body, Thalassa takes Mulhall's, and Henoch takes Spock's. They are all overwhelmed by the pleasure of having physical bodies after so many years. Almost immediately, though, Henoch plots to kill Sargon in Kirk's body. While Sargon leads the effort to build androids for them to occupy, Henoch attempts to lure Thalassa into agreeing that they should keep their host bodies.
Henoch telepathically forces Nurse Chapel to poison Sargon (in Kirk's body) and then destroys the globe that houses Spock's mind. McCoy and Nurse Chapel keep Kirk's body on life support, but his mind is still trapped in Sargon's receptacle. Henoch has completed an artificial body for Thalassa, but she refuses to transfer her consciousness into it. Instead, she goes to sickbay and offers McCoy a chance to save Kirk in return for keeping the human body. McCoy refuses, so she attacks him with her thoughts. But then she realizes what she's doing and breaks off her assault. Suddenly, she and McCoy hear Sargon's voice — he transferred his mind into the ship's computer, and he has a plan. Chapel arrives, and Thalassa orders McCoy out of the room. The room shakes, and a few seconds later Chapel walks out. When McCoy rushes back in, he finds Kirk and Mulhall restored to normal, and all the receptacles destroyed. Kirk orders McCoy to prepare a hypo with a deadly injection — Spock's mind is now dead, so now they must destroy Henoch.
By now Henoch has taken control of the Enterprise. On the bridge, McCoy attempts to inject him, but Henoch stops him and orders Nurse Chapel to inject the Doctor. She takes the hypo, but injects Spock's body instead. Henoch tries to move to another body, but Sargon stops him, and he falls to the floor. Chapel staggers, and Spock stands up. It turns out that Spock's consciousness had been transferred into Chapel's body, and that the injection wasn't really deadly — Sargon had manipulated the Doctor to believe it was because Henoch could read McCoy's thoughts.
Sargon and Thalassa realize that they cannot live in the physical world, but before they depart to roam the universe in their noncorporeal state, they inhabit Kirk's and Mulhall's bodies one last time so they can share a kiss.