Stardate 2715.1: The Enterprise arrives at the Tantalus V Penal Colony to beam down supplies. They have to call down to get the colony to lower the security force field so they can beam down the supplies. They then beam up one box of classified material and after Kirk leaves the room, a demented-looking man emerges from the box and attacks the transporter technician.
The Enterprise leaves orbit and Kirk discusses Dr. Adams, the revered head of the penal colony. The colony calls them and informs them that a violent inmate has escaped. Meanwhile, the stowaway has taken a uniform and gets past security, heading for the bridge during the red alert. They contact Dr. Adams who repeats the warning that the escaped inmate is clever and dangerous. The prisoner bursts onto the bridge and identifies himself as Van Gelder, but despite his phaser he begs for asylum and refuses to go back. Spock manages to get around him and dispose of him with a nerve pinch.
The Enterprise heads back to the penal colony while McCoy admits he can't make any determination as to Van Gelder's condition. The prisoner can't seem to make up his mind as to his identity, changing his story back and forth. Van Gelder tries to explain he is the director of the penal colony but is overwhelmed with mental agony and says his mind has been "erased." Spock confirms that a Dr. Van Gelder was assigned to the penal colony six months ago as Adams' associate. Kirk asks Adams as to Van Gelder's condition and Adams explains that Van Gelder was trying an experimental process. McCoy asserts that something doesn't sound right and files a log, which requires Kirk to investigate. Adams cheerfully agrees but asks that they limit contact so Kirk has McCoy find him a medical officer with psychiatric and penology experience.
Kirk leaves Van Gelder in sickbay to complete his investigations and goes to the transporter room to meet Dr. Noel. The two have had some history together at the science lab Christmas party. They beam down to the planet and descend in an elevator deep into the planet's surface. Dr. Adams greets them and lets Kirk keep his weapon. The captain calls up to the ship, although Adams has to drop the security screen to let him. Adams introduces Lethe, a former prisoner who has been reformed and now works on staff.
While Adams takes Kirk and Noel to see the device Van Gelder was testing on himself, the doctor himself rambles on about the "light." Adams shows them a room with a light and a chair, which he explains is a neutral neutralizer they use to quiet patients. The controls are simple and Noel claims the device is harmless. Adams explains that Van Gelder didn't bother to have anyone standing nearby when he experimented and the device wiped his mind. After the group leaves, the assistant Carl tells the patient undergoing treatment to forget everything, and to suffer pain whenever he attempts to remember.
Kirk checks in with the ship and after Adams leaves, Spock informs the captain that Van Gelder believes the captain is in danger. Kirk decides to spend the night over Van Gelder's objections. The doctor tries to control himself and warn that Kirk is in deadly danger. Spock reluctantly decides to use the Vulcan Mind Meld to link with Van Gelder's mind.
On the colony, Kirk comes to visit Noel and get her opinion, believing the patients seemed somewhat blank. He wants Noel to show him the neutralizer controls and use him as a test subject.
Spock merges his thoughts with Van Gelder's and the doctor reveals that Adams erased his memories and those of the other prisoners and replaced them with his own thoughts.
Noel tries the machine on Kirk and first blanks out his memory, then plants an impulse of hunger. Kirk is impressed by the supposedly ineffective device and this time Noel plants a suggestion that they got together at the Christmas party and he took her back to the cabin. However, Adams comes in, confines Noel, and plants even more intense memories of his romantic feelings for Noel. Adams then forces Kirk to remove first his phaser and then his communicator. When Kirk refuses the latter, Adams increases the neutralizer and drives him into agony.
The captain is confined to his quarters with Noel and still believes he's hopelessly infatuated with Noel. She tries to bring him out of it and he manages to remember the truth. He then pries open an air ventilator grille and sends her to cut off the power to the security screen. After she leaves, Adams' assistants take him back to the neutralizer room where the good doctor reprograms Kirk to trust him completely. Lethe informs Adams that Noel has gone and the doctor tortures Kirk for her location. Kirk collapses to the ground, unconscious, while Noel gets to the power room. She shuts down the power, cutting off the screen and the neutralizer. Kirk knocks out Adams and his assistant but another man knocks out Noel and restores the power. She shoves him into the power circuits, killing him.
Spock realizes the security screen is down and is beamed to the planet with a security guard not far behind. Noel leaves the power station just as Spock arrives and disables the screen for good. He turns on the rest of the power, leaving Adams caught in the neutralizer beam at full power. Kirk gets back to his quarters where Noel is and he starts kissing, and a bemused Spock comes in. Kirk realizes Adams is still in the treatment room and goes there to find that Adams has died, his mind emptied.
Later the Enterprise breaks orbit after Van Gelder assures them that he's recovered and the neutralizer dismantled. McCoy wonders how a man could die of loneliness but Kirk knows firsthand how it could happen.