Stardate 5476.3: A cluster of archaic chemically-fueled missiles attack the Enterprise, which goes to red alert. They easily destroy them and start tracking the missiles' back. In Sickbay, Chapel calls Kirk down over McCoy's objections. Once she leaves, McCoy informs the captain that one crewman has an incurable disease and one year to live: the ship's chief medical officer.
The source of the missiles is a large asteroid drifting through space, and they soon determine it's under power. The asteroid is hollow with a breathable atmosphere within, and on a collision course with an inhabited planet. Kirk takes Spock down to investigate but McCoy insists on going. They beam down and find themselves seemingly on a planet's surface, surrounded by metal man-sized cylinders. The cylinders open and men attack them, led by a woman. McCoy comes face-to-face with her, pauses, and is knocked out while the other two are taken captive. She has them taken below past the other inhabitants of the artificial asteroid. She takes them to a sacred chamber and forces them to kneel while speaking to a stone obelisk, the Oracle of the People. She shows them their weapons and then asks who they are. The Oracle speaks out, telling them to learn what it means to be their enemies, and electrifies them unconscious.
The landing party is taken to private quarters where McCoy takes longer to recover, and Kirk explains to Spock why. The doctor recovers consciousness and quickly realizes that Spock knows. An old man comes in to tend to them and warn of the power of the Oracle. He identifies their world as Yonada and tries to comprehend that they have come from "outside." He talks of how it is forbidden to climb the mountains, flinching in sudden pain. He manages to say that he managed to climb to the top of the mountain… and touch the sky. He then collapses in agony and dies. McCoy determines there's a glowing red substance beneath the skin on his forehead.
The priestess, Natira, comes in and has the old man's body taken away. She talks of how those who speak evil are punished by the Instrument of Obedience, then treats them as honored guests. She's clearly interested in McCoy and Kirk tells the doctor to chat with her while they go out and investigate. McCoy asks how the old man was punished but Natira refuses to speak of it. Instead she speaks of her attraction for him and asks him to stay as his mate. He tells her that he has only a year to live but she still wants him to stay, and they kiss.
Spock and Kirk find the Oracle room and discover the writing is in Fabrini, the language of an advanced culture. The Fabrina star went nova and they conclude the survivors were put on the asteroid-ship and now it is their descendents who travel through space. Spock deciphers the door lock but avoid the platform that activates the Oracle. They find a plaque representing the Fabrina star system. They hide behind the plaque when Natira enters the room and asks permission of the Oracle to bring McCoy into their civilization. The Oracle grants its permission but as she leaves, it senses Kirk and Spock and electrifies them, then orders their death.
McCoy agrees to stay but asks for mercy for Kirk and Spock. She agrees and he bids them farewell, despite the fact that if they can't stop the asteroid then they'll have to destroy it. They leave and Natira puts an Instrument of Obedience in McCoy's forehead. She then opens the plaque and shows him the Book of the People, admitting she hasn't read it and is content to wait until they arrive at the promised destination.
Kirk contacts Starfleet who informs to leave the matter to Starfleet. As they prepare to leave, they get a call from McCoy who informs them of what he's discovered. He collapses in pain before he can say anything further. Kirk and Spock beam down and remove the device while restraining Natira. He directs them to the Oracle room while Kirk tries to convince Natira she is living on a ship. When she starts to seriously listen, her own Instrument of Obedience inflicts pain. She goes to the Oracle without warning the guards. She demands the truth and collapses, and the landing party comes in. McCoy removes her Instrument of Obedience as she says she believes him. When they go to get the book, the Oracle heats the room up. Spock finds the instructions to open the altar, revealing a control room beyond. Spock neutralizes the heating elements while McCoy assures Natira that they will put the asteroid-ship back on course. She now understands the true purpose of the creators and insists on staying on Yonada. McCoy wants her to come with him while he seeks a cure but she refuses to abandon her people.
Kirk and Spock put the ship on course, and Spock finds the total knowledge of the Fabrini… including their medical knowledge. They administer the cure to McCoy and Kirk assures him that they'll be there when Yonada makes planet fall at their intended destination.