The Enterprise responds to a distress call from a scientific colony on Triacus. Kirk, Spock, and McCoy beam down and discover almost all of the adults, dead. The colony leader, Professor Starnes, dies even as they look on. They determine that they all took a deadly poison, cyalodin. Kirk plays back Starnes' tricorder and listens as he talks of how there is an enemy within and they have to destroy themselves. Suddenly the five colony children run over. They seem unconcerned about their parents and introduce themselves. They start chanting cheerfully among the corpses of their parents.
Later, the landing party buries the colony members but the children are more interested in playing. Kirk is skeptical of McCoy's suggestion that they are blocking out grief for their parents but McCoy doesn't have any other answer until he can make specific tests. McCoy advises against questioning the children out of concern it could damage the children's psyche. Kirk tells the children to assemble so they can beam up to the ship with McCoy. Spock suggests that the suicides were somehow induced, possibly through chemical means. Kirk wonders if the children were spared for some purpose. Spock notes that the planet is uninhabited but picks up a signal from a nearby cage. They enter and Kirk suddenly becomes strongly but briefly panic-stricken. He quickly leaves the caves and reverts to normal.
Aboard the Enterprise, Chapel provides the children with ice cream. Meanwhile, McCoy tells Kirk that the children test normally and he doesn't have any answers. Kirk refuses to leave until he finds out what happened on the planet. He visits the children and brings up their parents on Triacus and how the children must miss them. The kids seem unconcerned and start playing again. The oldest boy, Tommy Starnes, asks for more ice cream and Kirk tells him it's too close to supper. Tommy and the others say he's just like the others. As Chapel herds the other children away, Kirk asks Tommy what he saw on the planet. Tommy remembers that his father was upset but claims he was always upset, just like Kirk. He's not upset about leaving his parents and claims his parents were always busy and now they're happy on the planet. Kirk orders Security to watch the children.
In their cabin, the children chant and call out to a Friendly Angel. A glowing green angelic figure appears and compliments them, saying they've done well. Now they must go to a Federation settlement, Marcos 12, and stop Kirk when he sets a course to a Starbase. The angel, Gorgan, says that they will have a million friends on Marcos 12 and they will kill the others. Gorgan promises that they will have an entire universe to play in but first they must take control of the crew.
Spock brings Starnes' log tapes to the captain. They play them back and watch as Starnes talks of a growing feeling of uneasiness among the adults. Other dated recordings show that Starnes became increasingly anxious as time passed. They also found the remains of a civilization and one of the members took refuge in the cave. As Starnes starts to talk about an unseen force, Tommy arrives on the bridge. He makes a gesture and the playback machine scrambles. Tommy asks if he can be taken to Marcos 12 but Kirk says it's not within their course. He asks to stay on the bridge and watch and Kirk agrees, and then goes to his quarters with Spock and McCoy. Once Kirk is gone, Tommy takes mental control of Sulu and the others and force them to unknowingly set course for Marcos 12 while believing they're still in orbit. Uhura briefly notices they've left orbit but Tommy takes control of her as well.
In Auxiliary Control, another of the children uses his powers to render a crewman unable to see that they've left orbit. When Scotty notices the problem, he tries to convince the crewman, who insists he's losing control. Scotty struggles but other controlled crewman subdue him,
In Kirk's quarters, the captain, Spock, and McCoy listen as Starnes speaks of how his mind is being influenced. He resolves that they must destroy themselves. They realize that evil might seek to mislead the children. Spock speaks of how a band of marauders passed through the system and that the evil was waiting for a catalyst to set it into motion once more. Kirk suspects the evil is at large and McCoy warns that releasing the children's grief could be harmful. The captain refuses to endanger the ship and realizes that Starnes tried to ask for a ship. Kirk wonders who he wanted to summon a ship for.
Kirk and Spock go to the transporter room to send a survey team down. Once the new team is down, Kirk has the first crew beamed up. Spock realizes that he can't lock on and they're no longer orbiting Triacus. Kirk realizes that the men he beamed down are now dead. They check the monitor screen and confirm they're no longer in orbit. He and Spock go to the bridge to find the oblivious crew and the children, chanting. Gorgan appears and warns that the "enemy" have discovered their operation. He tells the children to summon the "east"within those who oppose them, summoning their greatest fears, and then disappears.
When Kirk orders Sulu to ignore what he sees and set a course, Tommy makes the helmsman see a tunnel of knives. Kirk has Uhura contact the starbase and Tommy forces her to see a reflection of her diseased self, immobilizing her in fear. The captain orders Spock to make the transmission but the Vulcan is unconcerned, stating the bridge is under complete control. When he attempts to make the call anyway, Tommy increases his control, preventing him from doing anything. His orders to the security crew become scrambled and Kirk advances on Tommy. Tommy uses his powers to give Kirk a massive fear of losing command. Spock gets him off the bridge and into the turbolift. With Spock's help, Kirk manages to face his fear and overcome it.
Kirk and Spock head for Auxiliary Control only to find Scotty there. The engineer refuses to take orders, insisting that he can't upset the balance of the systems. One of the children watches them and repeats his influence, forcing Scotty to tell Kirk to leave before they kill him. Kirk tries to go for the controls but the crewmen force them to retreat. Spock warns Kirk that the children may not be aware of the evil they're doing, but they soon may have no choice but to kill them.
Chekov arrives with two security officers and tells Kirk and Spock that they are under arrest. Chekov glances over at Tommy, who has accompanied them. When Kirk tries to get through to them, Chekov draws a phaser and says he'll kill them if necessary. Kirk and Spock jump the men and manage to subdue them. Tommy runs off in terror.
Kirk goes to the bridge where Tommy is sitting in the captain's chair. Kirk tells him that the crew would not take them to Marcos if they understood. He demands to see Gorgan but the children refuse to call him. Kirk says that Gorgan is a coward and orders Spock to play back the chant the children used to summon Gorgan. The alien appears and boasts that it is too late to stop him and the children. When Gorgan says that he is strong but too gentle and must be killed just like the parents, Kirk has Spock play back the video recordings Starnes took of the children playing with their parents on Triacus. As the scenes of happy family life play, they switch to shots of the parents, dead. Gorgan insists that the parents had to be eliminated and tries to rally his soldiers. The children break into tears and Gorgan's face begins to deteriorate. Kirk tells the children not to be afraid as Gorgan disappears, his power conquered. The crew's senses are restored to normal and McCoy is relieved to see the children expressing their grief normally.