The USS Enterprise races to Gravesworld, inhabited by Dr. Ira Graves, an elderly and respected scientist. Graves conducts his work in private isolation and has only one colleague with him, a young woman named Kareen Brianon. The Enterprise has received a plea for medical assistance from Kareen, and because Graves is working on critical research, Starfleet orders it a priority to help him.
Approaching the planet, the Enterprise receives a distress call from the transport ship Constantinople. Captain Picard makes a risky near-warp transport, beaming down an away team without stopping the ship and then proceeding to the transport ship. Dr. Pulaski remains onboard to help the Constantinople, so her Vulcan medical assistant, Dr. Selar, is beamed down, along with Lt. Commander Data, Counselor Troi and Lieutenant Worf.
They discover Kareen has asked for help behind Graves' back, because he doesn't like people or doctors. Graves admires Data, and says that he taught Data's creator, Noonien Soong, everything he knew, making him Data's "grandfather". Selar medically scans Graves and diagnoses him in the terminal stage of Darnay's disease. She says there is nothing she can do, and gives him three weeks to live.
Graves whistles to Data an ancient song called "If I Only Had a Heart", a lament sung by the "Tin Man", a mechanical-man who longed to be human. He finds out he had been human all along and never realized it. Graves mentions it must be hard, so close to being human but never knowing pain, lust, envy or desire. Graves then shows Data a sophisticated computer and mentions his plan for immortality - he has developed a way to transfer his consciousness - all his knowledge, thoughts and memories - into a machine. Graves says that Data will never know death. Data retorts that he has an "off switch" and compares being shutdown with death. Graves wonders where Soong would have placed this switch, then immediately adds "No... let me guess".
Data informs the away team that Dr. Graves has just died in his arms. Kareen and the away team return to the Enterprise, which leaves for Starbase 6. A funeral is held in the transporter room to beam Graves' casket into space. Captain Picard says a few words and invites others to speak. Data steps forward and gives a lengthy, hyperbolic praise of Dr. Graves. He says,"To know him was to love him. To love him was to know him. All those who knew him, loved him, and those who did not know him also loved him, but from afar." Picard interrupts and ends the ceremony, and the casket is beamed into space.
Wesley Crusher asks Data about his speech; Data replies that Wesley's childish mind would never comprehend its wisdom. Commander Riker overhears the comment, and asks Data if he is turning into a philosopher. Data claims he is "scholar, artist, philosopher, lover, genius." Picard shows Kareen the stars on the viewscreen; she is impressed by their beauty. Picard says that he knows of her interest in science; Data comments under his breath "...and I know of your interest in HER!" Picard challenges Data, and after more insubordination and insolence, Picard asks him if he is malfunctioning, and sends him to engineering to be examined.
Nothing is found physically wrong, so Troi suggests that she conduct a psychotronic stability test to see if something is mentally wrong with Data. She conducts the test hooking Data up to skin probes and displaying a series of images that attempt to provoke emotional responses. She reports to the Captain that she has detected two personalities within Data. The Data they know is quickly being taken over by a dominant alien persona which is unbalanced, paranoid, and violent. If they don't stop it, they could lose the Data they know forever. Troi tells Picard that the alien persona has an extreme hatred of authority.
Data/Graves reveals to Kareen who he really is, that he has transferred his consciousness; he can show his love for her as he always wanted, now he is immortal. He will build an android body for her, and they will live together forever. Kareen is horrified, she wants to live a normal life. This angers Data/Graves, and he squeezes her hands, hurting her with his super-strength.
Picard tracks Data/Graves down to engineering. He tells him that he knows who he is, and asks him to give Data's body back; then finds Geordi lying unconscious. He argues that Data is unique and Graves has no rights over him. He also says that the experiment has gone wrong, hurting Geordi and Kareen, and that he must end it now before more people get hurt. Data/Graves gets angry and strikes Picard unconscious before realising the truth of his words.
Dr. Pulaski revives Picard, and he rushes to find Data who has returned to his quarters. Data is found lying unconscious on the floor in the middle of his room. La Forge wakes him to find that Graves has left, and he is his old self. Kareen realizes that Graves has transferred his knowledge into the Enterprise computer, but his consciousness and personality are lost forever.