On stardate 5630.3, the starship USS Enterprise receives a distress call from a human colony on Beta XII-A. The colony is apparently under attack by an unknown vessel. On arrival, the Enterprise finds no sign of an enemy ship. Captain Kirk beams down with a landing party to investigate the planet but they find no evidence of a human settlement ever having been there.
Back in space, the Enterprise goes on alert as a Klingon vessel suddenly pulls into orbit with them. However, as the crew watch, a series of strange explosions occur on the Klingon ship that leave it dead in space. The surviving crew of the Klingon ship, led by Commander Kang, beams down to the planet where they quickly capture Kirk's landing party.
Kang denies attacking any human colony but asserts that his ship was fired upon unprovoked by the Enterprise, and he demands that Kirk surrender his ship. After a struggle, Kirk pretends to agree and surrender quietly, however, he manages to trigger a security alert to Mr. Spock on the bridge just before beaming up. When Kirk's team, along with their captors, returns to the Enterprise, Kang and his crew are "held" in the transporter beam, rematerializing later and finding themselves surrounded by an armed security force. The Klingons surrender.
Unbeknownst to the crew, a strange swirl of energy manages to sneak on board the Enterprise undetected. The entity interfaces with the ship's main computer and suddenly, the Enterprise then jumps into warp at maximum speed on an uncontrolled heading to the edge of the galaxy. Fear and anxiety begin to rise as the ship races out of control. Emergency bulkheads begin to close throughout the ship isolating Kirk and some of his men with the Klingons.
At the same time, mysterious racks of bladed weapons appear throughout the ship and the crew's phasers disappear, replaced by swords and knives. Now armed with the primitive weapons, a savage melee breaks out between the Klingons and the Enterprise crew. Kirk manages to fight his way back to the bridge where Spock reports that he has detected an alien presence that seems to have taken over the ship. Spock begins to work on a way of getting rid of it.
Meanwhile, the Klingons have taken over engineering and begin to shut down life support to the rest of the ship. Oddly, their attempts are futile and life support is restored completely on its own. In fact, severely injured crew who fought during the skirmish find their wounds have rapidly healed, almost as if to keep both sides of the battle on a matched footing. Kirk and Spock surmise that the alien intruder is playing some kind of twisted wargame, but its motives are unknown.
Kirk wants his crew to stop fighting, but they find themselves uncontrollably driven to violence through fearful paranoia. Kirk and Spock decide to try to reach Kang, in order to alert him to the situation, and to reason with him. Meanwhile, Mr. Chekov roams the ship seeking revenge for the murder of his nonexistent brother. When he finds the Klingon female Mara, who is Kang's wife and science officer, he threatens to rape and kill her. Mara is rescued by Kirk and Spock who manage to knock Chekov out.
Mara remains wary of Kirk's help. She tells him she has heard that Klingons that are captured are put into Federation concentration camps for later execution or experiments. Kirk tries to calm her down telling her there are no such camps, and that an alien force is behind what is going on. Mara still refuses to believe Kirk, however the alien entity finally makes an appearance just outside sickbay. The being lingers for a moment and then vanishes through a bulkhead. Spock believes the entity may be feeding off everyone's negative emotions, especially fear and anger. He suggests it may have faked the colony distress call and set up this battle between the crew and Klingons so that it has a convenient source of nourishment.
Having seen the alien herself, Mara is finally convinced and leads Kirk to her husband Kang, who remains holed up in engineering. Mara tries to explain what is going on to her husband, but he doesn't believe it and demands a final duel to the death with Kirk. The two ship captains begin their swordfight and soon the entity appears to feed off their anger.
Despite the presence of the being, Kang continues fighting. Kirk however struggles to ask Kang if he would like to spend the next thousand lifetimes satisfying the alien's twisted desires. Mara also convinces her husband to lay down his arms. Kang now realizes the fight is pointless and agrees to a truce. To combat the alien entity, the Klingons and Enterprise crew begin to show goodwill and positive emotion toward each other. This finally drives the weakened alien from the ship.