When Midgwis was discovered by the Klingons, one of the Midgwins encountered by the Klingons was Geshkerroth, who the scouts had attacked. Geshkerroth was able to use his powerful telepathic abilities to destroy the Klingon scouts, whom he and other Midgwins refered to as Hungries. Geshkerroth and many other Midgwins came to believe that these Hungries would destroy the Midgwin people.
When the USS Enterprise visited the planet to place a survey team from the Federation Xenological Institute on the planet, Geshkerroth saw an opportunity to turn all Midgwins against the alien visitors. Geshkerroth was able to take control of the body of Captain James T. Kirk while the Enterprise landing party was beaming up to the starship. He forced the consciousness of Captain James T. Kirk from his body during this process.
For the next several days, Captain Kirk survived as pure energy. At times he was able to concentrate just enough to affect objects in the physical world, leading the crew of the Enterprise to believe that a poltergeist or other alien lifeform on board. Meanwhile, Geshkerroth had forced himself on Doctor Helen Gordon. Knowing that Gordon was suspicious that it wasn't Jim Kirk inhabiting Kirk's body, he tried to kill her by poisoning her - which gave him the needed excuse to kill Captain Kirk.
By this time, Commander Spock also became suspicious that Kirk was acting strangely. Geshkerroth attempted to murder Spock by drawing him into the shuttlebay and opening the bay to space. However Kirk was able to warn Doctor Gordon that Spock was trapped on the hangar bay by writing a message in a steamed up mirror in sickbay. After Spock's life was saved, he realized that the "poltergeist" on the Enterprise was actually Captain Kirk. By then Kirk was exhausted, and almost lost his remaining cohesion. Spock was able to build an artifical intelligence computer program so that Kirk would have a place to house his consciousness while the Enterprise.
As far as Geshkerroth and most of the remainder of the crew were concerned, Spock died when he was blown out into space from the hangar deck. Spock hid in a compartment in the secondary hull for the next several days, working with Captain Kirk to determine Geshkerroth's intentions. Geshkerroth ordered the Enterprise to return to Midgwins, where he attempted to use the ship's phasers to destroy the Bindigo Warren and kill patriarch Kailin Arxoras. Kirk left the computer at that time to distract Geshkerroth, and Spock quickly adjusted the Enterprise phasers so that when Geshkerroth fired all he did was blast a large hole in the middle of an uninhabited desert.
Geshkerroth then left Captain Kirk's body, and returned to the surface of the planet. Kailin Arxoras, who had been filled in by Doctor Gordon on what Geshkerroth had done, responded by casting Geshkerroth out of the Consciousness Web - or the shared telepathic experiences of the community. Arxoras was able to help guide Captain Kirk's consciousness back to his body afterwards. A short time later Yarblis Geshkerroth sought forgiveness from Doctor Gordon for harming her, and then committed suicide by throwing himself into a nearby river. (TOS novel: Ghost-Walker).