When the U.S.S. Enterprise answers a distress call from a small planet, the landing party is captured by a group of agents from the Kelvan empire, located in the distant Andromeda galaxy. The Kelvans' purpose is to find planets suitable for colonization. However, their own ship was destroyed and now they need the Enterprise to make the 300-year journey home. To utilize the starship, the Kelvans — huge, tentacled creatures — take on human form. After several attempts at escape, Kirk accepts his fate and agrees to let the aliens take over his ship. The Kelvans use their technology to transform all but essential Enterprise personnel into small "cubes" which, unless broken or damaged, can be restored to human beings.
Recognizing that the Kelvans, in their new human bodies, are discovering human sensation and emotion, the remaining crew attempts to foster dissent amongst the aliens: Scotty succeeds in gettting one of them drunk, McCoy injects an irritant into another, and Kirk makes romantic overtures to the Kelvan leader's woman. With the Kelvans thus distracted, Kirk and the crew are able to regain control of the ship.
Kirk points out to Rojan, the Kelvan leader, that the Kelvans are already becoming less like they were before by encountering the humans. In 300 years, their descendants will be so human-like that they won't be able to live among their people on Kelva. Rojan sees the logic in his argument and sends a robot probe to Kelva, reporting what has happened. Pledging to restore the Enterprise crew, Rojan accepts Kirk's offer that the Enterprise find the Kelvans a Class-M planet to colonize.