Star Trek: The Changeling

Around stardate 3541.9, the starship USS Enterprise, under the command of Captain James T. Kirk, investigates a distress call from the Malurian star system. Upon arrival, Mr. Spock reports that all life in the system has been destroyed and Malur, a world with a recorded population of 4 billion, is now devoid of life, including the Federation science team that was on the planet.
Suddenly, the Enterprise's shields activate when a meter-long cylindrical object attacks the ship with an energy bolt equivalent to the strength of 90 photon torpedoes. Kirk orders a return fire, but the ship's weapon energy is simply absorbed by the object. Kirk then transmits a hail and the object stops firing. Curiously, the object responds and requests in-person communication with the Captain, and allows itself to be beamed aboard the ship.
Once on board, the object identifies itself as a space probe named Nomad, and oddly refers to Captain Kirk as "the Creator". Checking historical records, Mr. Spock finds information that the Nomad space probe was launched from Earth during the early 21st Century; its mission was to explore the galaxy, just like the Enterprise.
Nomad mistakenly believes that Captain Kirk is actually Dr. Jackson Roykirk, the original scientist who created it. Nomad however, corrects Mr. Spock by saying that its mission is to "find and sterilize imperfection". Since Nomad's definition of imperfect includes all living things, it travels from world to world, killing everything. Repulsed by the machine's words, Kirk decides to play along with Nomad's mistake, and tells Nomad not to "sterilize" anything further, which for now, it obeys.
Nomad has powerful abilities, which the crew discovers when Kirk leaves Nomad to be watched by Lt. Singh. However, Nomad leaves to investigate singing it overhears on the intercom and discovers the source: Lt. Uhura. Nomad asks Uhura about this strange form of communication. When Uhura responds she's singing music, Nomad asks her to "think about music" while it probes her mind, but instead erases her memory. When Mr. Scott tries to intervene, Nomad simply kills him. Spock rebukes Nomad for harming Uhura; Nomad retorts that she is "a mass of conflicting impulses". Kirk is very disgusted over what has just happened, but Nomad offers to "repair the Scott unit", claiming that it was only acting in self-defense. In a display of its powers, Nomad returns Scotty to life. Kirk then orders Nomad to repair Uhura, which it claims it cannot do since it has erased her "knowledge banks". A nurse looks her over. Spock suggests that if there's no damage to her brain, she can be re-educated. There are sufficient tapes in the computer library to do this, and Chapel is assigned to work with Uhura.
Nomad is then escorted to a holding area where Spock attempts to study it further. Spock is not able to learn full details from his scans, and therefore resorts to a mind meld with the machine. (Just how Spock is able to mind meld with a machine is uncertain). Spock discovers that Nomad collided with an alien probe called TONRU, designed to obtain and sterilize soil samples from other planets. The collision severely damaged both probes, and during the accident the programming of both machines somehow combined. Nomad confused TONRU's mission directives, interpreting them to mean "sterilize imperfections". Spock is disturbed by the experience of the 'machine-to-Vulcan' mind meld, so much so that Kirk is forced to pull him away when he starts to exhibit the coldness of Nomad's logic.
Kirk now realizes Nomad is a device completely without conscience that is capable of wiping out entire solar systems in the blink of an eye, and there seems to be no way to stop it. All Kirk can do is wait and once again confines Nomad to the holding area. Nomad however has other plans, and it passes right through the security field, killing two guards who attempt to stop it. Nomad then makes its way to the engine room where it improves the efficiency of the ship's engines 57% by increasing the matter-antimatter reaction rate. Kirk orders Nomad to reverse the changes, as the Enterprise cannot handle the stress.
Kirk confronts Nomad, telling it that its sterilization of biological units is illogical, since the creator is a biological unit. Kirk tries to get the probe to return to the holding cell, but it kills the two security guards sent to escort it. Nomad then heads to sickbay and examines Kirk's medical files. Nurse Chapel is attacked when she tries to stop it. Nomad then decides to shut down all life support systems throughout the ship to destroy the imperfect units that "infest" the Enterprise.
Kirk again confronts Nomad and questions its logic of destroying imperfect beings. Kirk tells Nomad that Nomad itself has made a mistake, something only an imperfect being can do. He tells Nomad that its creator is Jackson Roykirk, not himself, and that Nomad is in error. Realizing its own imperfections, Nomad is caught in a logic loop, and begins to execute its primary function on itself. The machine begins self-destruction, shaking about in place instead of steadily hovering, its simulated voice rising in pitch. The ultra-logical Mr. Spock, who has been watching this confrontation, compliments Kirk, saying: "Your logic is impeccable, Captain. We are in grave danger." At the last moment, Kirk has Nomad rushed to the transporter room and beamed into space. Seconds after transport an explosion is detected near the Enterprise and Nomad is no more.