In the 22nd century, rising sea levels from global warming have wiped out coastal cities and altered the world's climate. With the human population in decline, nations have created humanoid robots called mechas to fulfill various roles. In Madison, New Jersey, David, an 11-year-old prototype mecha child capable of love, is given to Henry Swinton and his wife Monica, whose son Martin is in suspended animation. Monica initially feels uncomfortable but warms to David after he is activated and imprinted. David befriends Teddy, Martin's robotic teddy bear. After Martin is cured and brought home, he goads David into cutting off a piece of Monica's hair. Later, David accidentally pokes Monica's eye with scissors. During a pool party, David reacts to being poked with a knife and both he and Martin fall into the pool. Martin is saved, but David is blamed. Henry convinces Monica to return David to his creators for destruction, but instead, she abandons him in the woods with Teddy. David, believing that becoming human will regain Monica's love, decides to find the Blue Fairy. David and Teddy are captured by the "Flesh Fair", where obsolete mechas are destroyed. David pleads for his life, and the audience allows him to escape with Gigolo Joe, a mecha framed for murder. They travel to Rouge City, where "Dr. Know", a holographic answer engine, directs them to the ruins of New York City and suggests that the Blue Fairy may help. David meets Professor Hobby, who shows him copies of himself, including female variants. Disheartened, David attempts suicide, but Joe rescues him. They find the Blue Fairy, which turns out to be a statue. David repeatedly asks the statue to turn him into a real boy until his power source is depleted. Two thousand years later, humanity is extinct and Manhattan is buried under ice. Mechas have evolved, and a group called the Specialists resurrect David and Teddy. They reconstruct the Swinton home from David's memories and explain that he cannot become human. However, they recreate Monica using genetic material from the strand of hair Teddy kept. Monica can live for only one day. David spends his happiest day with Monica, and as she falls asleep, she tells him she has always loved him. David lies down next to her and closes his eyes.