The U.S.S. Enterprise is scanned by a powerful energy source coming from the planet Excalbia. The starship had been sent to survey the planet, but it was thought to consist of nothing but a lavalike surface without inhabitants.
The image of Abraham Lincoln appears in space and requests to be beamed aboard, claiming to be the genuine Lincoln. Against McCoy's objections, Kirk and Spock beam the entity aboard. They accept his offer to visit Excalbia, where a rock-like creature named Yarnek appears. Yarnek declares that the Enterprise officers are to participate in a battle between good and evil. This is to teach the Excalbians about humanoid concepts. Fighting for the "good" are, Kirk, Spock, Lincoln and Surak, founder of the present Vulcan culture. On the "bad" side are, Genghis Khan, Colonel Green, Zora — a vicious killer, and Kahless, father of the Klingon Empire as it was now known.
When the Enterprise officers refuse to fight, Yarnek freezes the starship's engines, starting a breakdown of the matter/antimatter shielding. If Kirk doesn't win, the ship will explode in four hours. There is much plotting and counter-plotting, until only Kirk, Spock, Khan and Zora remain alive. After some philosophical discussion regarding "good" and "evil," Yarnek returns Kirk and Spock to the U.S.S. Enterprise and frees the ship.