The Enterprise is enroute to peacekeeping duties at the twin worlds of Arima and Mazda, in the solar system of R-517. In a briefing with senior members of the crew, Kirk explains the background of these two warring worlds. Early struggles for survival between the two primitive tribes of the planet had later turned into organized religious warfare. When their science had advanced far enough for space travel, one of the tribes had left Arima, to occupy the neighboring world of Mazda. The conflict between the two worlds continued in space. Eventually, the Federation Supreme Assembly had summoned the leaders of the two worlds to Earth, and ended their conflict for them. The Federation had decreed that a permanent Starfleet peacekeeping force would patrol the area, and that if either party violated the peace, they would be met with force and expelled from the Federation.
Mr. Sulu calls the captain to the bridge. The Enterprise is passing near the planetoid Quaraxus, and the planetoid itself appears to be expelling all sorts of objects into space, causing mayhem for the inhabitants below. Spock reports that sensors show a severe electromagnetic current of man-made origin on the surface. "Man-made?" Kirk says, "Who would be so insane as to... wait a minute! Doesn't Professor Whipple live on Quaraxus?" "I believe so!" Spock replies. Kirk orders the Science Officer to pull up Whipple's coordinates, and then the two men beam down to the surface. There, they discover a huge device which is converting electromagnetism into radio waves that encircle the planetoid. Professor Whipple is lying on the ground nearby, unconscious. Spock quickly shuts off the device, and the Captain revives Whipple.
The Professor explains that he was testing his new device for repelling meteorites, when a short circuit happened, and he blacked out. "Professor" says Kirk, "How many times have I warned you about your unorthodox experiments?"
"But that will have to wait!" he continues. "This delay was costly!" The Captain orders the ship to resume course at warp 3. He explains to Professor Whipple that the Mazdans worship a god named Grolgar, and the Arimans have a similar deity named Vengwal. "According to their scriptures" Kirk says, "a time will come when both gods will appear, to lead their followers in the final battle. That time is now. The 'Time of His Arrival'!" "Each side is mobilized for war", Spock adds, "a war that could wipe out both!" When the ship arrives at Arima and Mazda, Kirk, Spock and McCoy beam down to the Ariman temple first, to speak with the leaders of the planet.
Meanwhile, Professor Whipple has been watching the Enterprise transporter in operation, and is fascinated. "What a marvelous device!", he thinks. "But so cumbersome! I wonder, could it be adapted for portable remote control?" He takes a science tricorder left behind by Mr. Scott, and begins tinkering. On the planet surface, the landing party is speaking with the leader of Arima in a grand throne room. "On that throne will Vengwal appear, to lead us against the heretic Mazdans!" the man says. "It is decreed in our sacred writings he shall appear, just as Grolgar shall appear on his throne, in the Mazdan temple!" Back on the ship, Whipple activates his newly constructed "portable transporter." He is instantly transported to the surface of Mazda, and materializes sitting in the throne of the god Grolgar!
On the Enterprise, Whipple explains what happened to the Captain. "You've really done it this time!" Kirk says. "Look at this screen! See for yourself, Professor! Space fleets of both worlds, readying for combat! This could be the greatest massacre in history!" Uhura attempts to communicate with the space craft, but they do not respond. Kirk orders the deflector shields up, in case the ship is caught in a crossfire. "Deflector shield?" the Professor thinks, "By George, why not? With my expertise in magnetism, it should be a leadpipe cinch!" He sneaks off the bridge, and minutes later, leaves the Enterprise in a stolen shuttlecraft.
Kirk orders the transporter room to beam the Professor back to the Enterprise. However due to disturbances in space caused by his own device, Whipple is trapped in a state of electrical energy near the two space fleets, ghostlike in appearance. Both the Mazdans and Arimans watch in awe as their "god" floats in space alongside their warships. "Help!" shouts a scared Professor Whipple, "Can't someone put a stop to this nonsense?"
Scotty locates the trouble with the transporter beam, and brings the professor safely back aboard the Enterprise. The energy field generated by the shuttle craft dissipates into space. Both Arimans and Mazdans head back to their planets, thinking that Professor Whipple's cry for help was actually a command from their gods to live in peace, and shortly after agree to sign a peace treaty with each other.
As the Enterprise leaves orbit around the planets, Kirk tells the Professor that he has received a call from Quaraxus, with a warrant for his arrest! "Oh dear" says Whipple, "what will become of me now?" The Captain explains that he told Quaraxus of the Professor's "heroism" in stopping the war between the planets, and that they had agreed to drop the charges. "How can I ever thank you?" asks Whipple. "You can thank me by promising never again to engage in any experiments without proper authorization!" Kirk replies. "Oh, absolutely, Captain Kirk!" says Whipple. "Now, if you will excuse me, I think I may have found the bug that caused this tricorder to go awry!"