In late 2270, the Enterprise is following a propulsion trail, hoping to learn the origins of an alien space probe which scanned Earth and sent signals out into space, then self-destructed. They encounter a ship that traps the Enterprise in a force field, then takes on the holographic form of a winged serpent. Relief helmsman Ensign Walking Bear recognizes the hologram as Kukulkan.
When a voice reverberates throughout the Enterprise, warning them of a coming test, Walking Bear tells Captain Kirk how he knows of Kukulkan, a god of ancient Mayan-Aztec legend. Moments later, Walking Bear, Scotty, Dr. McCoy, and finally, Kirk, all disappear from Enterprise, teleported over to Kukulkan's vessel. There, they are shown a variety of "seeds" sown by Kukulkan, a gigantic city with elements of Egyptian, Japanese, Aztec, and Mayan cultures, and told to solve an unrevealed mystery. After some exploration, they reason that by using four serpent heads to reflect the sun into a crystal device on top of a pyramid, they can signal Kukulkan. The device activates and sends out a rainbow-hued explosion of light.
Kukulkan appears, and castigates them for the Enterprise firing on him — which Kirk reminds him was only in self defense — and for forgetting him, humanity's "master." He transports them to his intergalactic zoo, where alien specimens are kept happily, in holographic environments. They learn that centuries ago, Kukulkan tried to teach humanity peaceful ways, but his newest probe showed him that humanity later became violent and warlike. Not only did humankind forget him ... they forgot his teachings as well.
When Mr. Spock figures out a way to help Enterprise escape from the energy field and fires on Kukulkan's ship, Kirk and the others distract Kukulkan by freeing a dangerous Capellan Power Cat from his zoo. Once the beast is tranquilized, they reason with Kukulkan, telling him how humans have been working to find peace. Kukulkan allows them to leave, realizing that he's taught them all he can, but that his "children" have grown up. Kirk and his crew are reunited, and as Kukulkan's ship soars away, they discuss everything they learned — and could have learned — from the lonely god.