On stardate 4513.3, the Federation starship Enterprise, under the command of Captain James T. Kirk, is hijacked by an android who has been posing as Mr. Norman (Richard Tatro), a recently assigned crewman. The android seals off engineering and redirects the ship to an unknown planet at Warp 7. Any attempt to undo his tampering will likely destroy the ship. The planet is discovered to be populated with other androids.
When the crew arrives at the planet, Captain Kirk discovers that Harcourt Fenton Mudd, an outlaw whom Kirk has encountered previously, is the apparent "ruler" of the androids. Having previously escaped incarceration for his crimes, Mudd explains that he crashed his spaceship on the planet, and the androids took him in. He says that they are very accommodating, but refuse to let him go. During his stay, Mudd has acquired thousands of android women as servants as well as an android version of his estranged wife Stella (Kay Elliot), which nags Mudd incessantly until being commanded to "shut up", at which point she deactivates.
The androids tell Kirk they were built by a people from the Andromeda Galaxy, but their creators were destroyed by a supernova, and the robots were left to fend for themselves. First Officer Spock (Leonard Nimoy) discovers there are over 200,000 of these androids that may be controlled by some as yet unseen central operator.
Mudd orders the androids to beam up to the Enterprise to fetch the rest of the crew. The crew are rounded up and brought down; Ensign Chekov (Walter Koenig) finds a pampered existence by the service of hundreds of beautiful android women to be not such a bad idea. Even Lt. Uhura (Nichelle Nichols) is impressed when she finds that she can live forever in an immortal android body. In the meantime, Mudd plots to escape by taking over the now-deserted Enterprise, but is stopped from carrying out his plans by the androids.