For the World Is Hollow and I Have Touched the Sky
At the same time McCoy discovers that he has a year to live, the U.S.S. Enterprise encounters the asteroid Yonada which is determined to be artificially propelled. Its center is occupied by humanoids, whose ancestors built the asteroid "vessel" in an effort to escape the destruction of their solar system. However, the controls have become defective and Yonada is heading for collision with a Federation planet.
The people are ruled by Natira, a priestess who takes her orders from the central computer. While Kirk and Spock search for the central controls that will redirect the ship, McCoy and Natira fall in love. Kirk and Spock return to the U.S.S. Enterprise but McCoy, wishing to spend what little time he has left with the woman he's come to love, stays behind, marries Natira and accepts the "Instrument of Obedience" which punishes wrong thinking.
Soon after the marriage, McCoy calls Kirk, telling him that he may have found the controls for the asteroid. However, he is struck down by the "Instrument of Obedience" before he can tell them where. Kirk and Spock beam back to Yonada, remove the sensor from McCoy, and locate the controls. They manage to put Yonada back on course. In deciphering the computer's library, Spock finds a cure for McCoy's disease, and the doctor returns to the U.S.S. Enterprise. Natira must stay on Yonada to guide her people and so bids McCoy good-bye.