Stardate 5843.7: The Enterprise is stricken with Rigelian Fever and they need ryetalyn, the only known antidote. They've detected it on a small planet in the Omega system and Kirk, McCoy, and Spock beam down with four hours to spare. Spock detects a human life form despite the fact the ship's sensors showed nothing. As they go for the ryetalyn, a floating robot confronts them and opens fire. When they try to return fire, they find their phasers inoperative. The robot moves in… and a white-haired man steps forward to order it to stop. The man introduces himself as Flint and reveals he knows who they are, and orders them to leave or he'll kill them. Kirk calls his bluff, ordering Scotty to open fire on their location if Flint doesn't yield. Flint seems more amused then concerned but yields, describing the bubonic plague and acknowledging that the crew will die the same way. Flint gives them two hours and orders his robot, M-4, to gather the ryetalyn. He then invites them to his luxurious palace.
Flint provides them with hospitality and the landing party notices a rare collection of books. They are unaware that a woman is watching them on a monitor screen. Flint talks to her and she admits she has never seen another living being, but Flint assures her that even Spock isn't her intellectual equal. The woman, Rayna, asks to meet them despite Flint's reluctance. He kisses her but she doesn't respond, but does ask him to give her the opportunity and he agrees.
McCoy finds a 100-year-old bottle of Saurian brandy and pours drinks, while Spock admires Flint's paintings and notes they are uncatalogued da Vincis made with contemporary pigments and paper. Kirk orders Spock to scan Flint to see if he's human, then has Scotty run a background check on Flint. They're interrupted when M-4 brings the ryetalyn in. Flint arrives to say that M-4 can prepare it for distillation and invites them to stay for dinner. He then introduces Rayna, who he identifies as an orphan that he has taken on as a ward and provided for her extensive education.
While McCoy accompanies M4 to the laboratory, Flint offers them conversation and games. Kirk, clearly smitten with Rayna, agrees to a game of billiards. Flint insists that they are still barbarians despite Kirk's protests. When Spock examines the sheet music of a waltz on Flint's piano, Flint invites him to play and Kirk dances with Rayna while her ward watches with interest. McCoy arrives to reveal that the ryetalyn is contaminated and useless. Flint offers to oversee the gathering of more ryetalyn with McCoy's assistance. Spock notes that the Brahms waltz he played is in Brahms' own hand but on contemporary paper.
Kirk goes to the laboratory where he finds Rayna. He notices a closed door and wonders what lies beyond it, and Rayna doesn't know what lies beyond it either. She admits she's troubled and Kirk holds her. The M-4 robot arrives and advances on Kirk, who tries to find cover without success after discovering his phaser has been rendered useless again. It ignores Rayna and prepares to kill Kirk… and Spock arrives to disintegrate it with his phaser.
They confront Flint, who apologizes saying the robot misinterpreted Kirk's actions as an attack on Rayna. An angry Kirk prepares to fight Flint, who activates another robot, M-5. Flint goes to the laboratory, ordering Rayna to come with him. Once alone, Spock warns the captain that should ignore Rayna and Flint loves her. However, they wonder why Flint had them dance earlier. Kirk calls Scotty, who confirms that the crew is almost completely incapacitated and Flint has no records. The planet was purchased by a Mr. Brack 30 years ago. Spock reveals he has determined that Flint is human but with odd biological readings, including an indication of extreme age on the order of 6,000 years. They have only two hours and 18 minutes and while Kirk wonders why Flint may be keeping them, Flint and Rayna watch them secretly and Flint denies sending the robot to kill Kirk. He tells her to say her farewells.
Scotty confirms that Rayna has no record as well and Kirk and Spock go to find McCoy. Rayna arrives and Kirk sends Spock on ahead while he talks to her alone. Kirk doesn't' want to say goodbye and kisses her, and she slowly kisses back. Flint secretly watches the entire thing and says that Kirk's usefulness is at an end.
McCoy tells Spock that the robot has taken the ryetalyn, while Kirk asks Rayna to come with him. She runs off and Kirk goes to the laboratory. Spock detects the ryetalyn behind the sealed door which opens for them when they prepare to phaser it open. Spock offers to go in alone but the others insist on going as well.
Inside they find a larger laboratory and a table with the ryetalyn on it. However, the room also contains a covered body with a label: Rayna 16. Removing the cloth, they find a bald replica of Rayna. There are other bodies, labeled with earlier numbers and in various states of completion. Flint arrives and Spock notes that he is Brahms and da Vinci. Flint admits that he is both historical figures, and many more. He was born in 3834 B.C., and was a soldier who fell in battle but didn't die. Since then he has lived unaging and undying, moving from identity to identity before anyone could notice. Now he wants a perfect immortal mate, designed by his heart. Spock suspected but had hoped he was wrong. Flint says that Rayna will never know and the Enterprise crew must stay so as to not reveal his secret. Kirk orders the Enterprise out of orbit but Flint uses a handheld device to shrink the ship and materialize it on a table, its crew in stasis. Flint admits that he's finally seen emotion in Rayna, and she will turn to her. Rayna enters the room and Spock asks her what she will feel when they're gone. Kirk promises to keep his secret and Flint has no choice but to leave them unharmed so as to not rouse Rayna's anger.
Kirk goes to Rayna and realizes that he loves her, then attacks Flint. The two men fight while Rayna insists she won't be the cause of it. She begs them to stop and then declares she will choose what she wishes to do. Kirk notes that she's human but Flint insists she still belongs to him. Spock warns them but they push the issue, each asking Rayna to stay with them. She pauses, hesitates, and collapses. McCoy determines that she's dead and Spock explains that she couldn't reconcile her newfound emotions when she loved both of them.
Later, the Enterprise leaves orbit, the fever cured. Spock reports to Kirk who notes both he and Flint are lonely. He collapses into sleep and McCoy arrives to reveal that when Flint left Earth, he lost his immortality and will live out a normal lifespan. He berates Spock for not understanding the depths of the emotion that the captain is suffering from, and wishes that Kirk could forget. After McCoy leaves, Spock approaches the sleeping captain… and uses the Vulcan mindmeld to cause him to forget.