The crew of the U.S.S. Enterprise investigate the planet Sarpeidon whose sun is soon to go nova. Upon beaming to the surface, Kirk, Spock, and McCoy discover the inhabitants gone and a library containing the planet's accumulated knowledge.
Kirk, Spock and McCoy are surprised to find a lone inhabitant on the surface, Mr. Atoz, the librarian, who mistakes them for citizens of Sarpeidon. Mr. Atoz has been transferring people into the planet's past using a machine called the "atavachron." While investigating this unique technology, Kirk leaps to rescue a woman he hears screaming and ends transported to a period fraught with superstitions and witchcraft. Attempting to follow Kirk, Spock and McCoy enter the atavachron's portal to find themselves in a different time — Sarpeidon's ice age.
McCoy, who is close to freezing to death, and Spock are rescued by a beautiful woman, Zarabeth. While close to the portals they entered from, Kirk, Spock and McCoy can communicate with each other but little more. However, this is enough to get Kirk arrested for practicing witchcraft.
Spock increasingly finds himself attracted to Zarabeth, and disturbingly more emotional and irrational, and even goes against Vulcan custom by eating meat. McCoy convinces Spock that this time in Sarpeidon's past is linked to Vulcan's primitive past and that they must return to their own time. Zarabeth insists they cannot return to the present without dying.
In jail, Kirk is befriended by a lawyer, another traveler of Sarpeidon's present, who helps him escape to find the portal, and return to the library.
Zarabeth helps McCoy and Spock to the place where she found them. By following the sound of Kirk's voice, they find their portal and leap back into the library. Mr. Atoz leaps to his own designated past and the Enterprise, with Kirk, Spock, and McCoy safely aboard, warps from orbit just as the sun explodes.