The story takes place in the future where the greenhouse gases have caused the polar icecaps to melt, flooding coastal cities. To combat over-population, people wishing to have children must apply for a license.
The film starts in the offices of a company called Cybertronics, where its owner, Professor Allen Hobby (William Hurt), wishes to push mecha (aka robotic) technology, to make a creation that can love. When his colleagues mention their 'love units' Hobby corrects them: he is not talking physical love, but emotional love, such as that of a child for its mother.
The narrative then moves 18 months into the future where the Swintons, whose son Martin (Jake Thomas) is currently in cryostasis until a cure can be found for a debilitating disease he is stricken with. His mother Monica (Frances O'Connor) has not held up well emotionally under the conditions that have taken her son from her. Hoping to help her cope, her husband Henry (Sam Robards), a Cybertronics employee, takes part in a test wherein they would be able to be a family to the company's newest mecha: David (Haley Joel Osment), the culmination of Hobby's research to make a robot that can 'love.'
At first, Monica is angry, believing her husband is trying to 'replace' Martin. However, Monica tries to adapt to David. Henry also informs her that if they choose to keep David that she must 'imprint' herself upon him. However, if there was ever to come a time that she chose not to want him, due to the imprinting being permanent, David would need to be sent back to Cybertronics to be destroyed. After some time, Monica decides to perform the imprinting process; she reads a list of words that will activate David's emotional simulation. When she does, David calls her "mommy" and begins to act like a real child. To provide David with another form of companionship, she gives him a robotic teddy bear called Teddy, which once belonged to Martin.
Things appear to be going well for the Swintons, until one day, a cure brings Martin back to health. Martin looks upon David not as a human, but more as a 'supertoy' or a 'doll.' One day, Martin asks their mother to read them 'Pinocchio,' to which David becomes enamored by, in which the wooden puppet becomes a real boy thanks to the story's Blue Fairy.
Martin then tries to get David into trouble in a number of ways. First, he cajoles David into eating spinach, which causes David to malfunction and need cleaning. Another time, he tells David to cut off some of Monica's hair while she sleeps as a gesture of love, but the incident makes Henry think that David was trying to attack his wife.
At Martin's birthday party, one of his friends decides to test David, to see if he has a way to prevent himself from pain. The 'test' causes David to grab onto Martin, crying 'keep me safe.' The two fall into the Swinton's swimming pool, where it seems that David was attempting to drown Martin.
Henry decides that David is no longer safe, and convinces Monica to return David to be destroyed. Monica tries to take David to Cybertronics under the cover story of going on a picnic. However, she cannot bring herself to take David directly to Cybertronics and abandons him in a forest, along with Teddy. David becomes frightened and confused and he questions why he is being forced to leave his mother.
Meanwhile, a male-prostitute mecha, Gigolo Joe, arrives at the apartment of a woman he sees regularly. He changes his appearance to suit her and, entering the bedroom, finds her dead. Her husband appears and kisses his wife, saying "I might have killed you but you killed me first". Joe retreats, realizing that the woman's husband is framing him for the murder. Joe rushes out of the apartment building and cuts off his registration tag to avoid detection by the police.
Still in the forest, David concludes that his abandonment was because he is not real like Martin, and that if he were to find the Blue Fairy like in the story 'Pinocchio,' she could make him real, and he would then be able to go home. Journeying through the woods, he comes across a number of abandoned, obsolete and broken-down mechas searching through Cybertronics' junk piles for spare parts to repair themselves. The mechas are rounded up by a man named Lord Johnson-Johnson (Brendan Gleeson), and taken to a 'Flesh Fair' where mechas are destroyed for the amusement of anti-mecha fanatics. David is brought into the ring along with the mecha named Gigolo Joe. When a few buckets of acid are to be dropped on both himself and Joe, David cries out, showing fear like a real boy. The crowd revolts against Johnson-Johnson and amid the resulting riot, David and Joe are set free and leave.
Escaping into the nearby woods, David tells Joe of his search for the Blue Fairy. Joe is confident that they'll find her in a place called Rouge City. Hitching a ride with some teenagers, they make it to the city: a mecca of adult entertainment that rivals Las Vegas and Disneyland. Their journey takes them to a place where a knowledgeable computer representation of Einstein, called Dr Know (voiced by Robin Williams), tells them that the Blue Fairy can be found "at the end of the world where the lions weep". Joe explains to David that Dr Know must mean a place called 'Man-hattan,' as many mechas have gone to the end of the world and have never come back.
David is all for going to 'Man-hattan' despite the danger. However, Joe tries to deter him, saying that it could be a trap. As David and Joe leave the building, Joe is accosted by officers, who have come to arrest him for murder, a fact David is unaware of. Seeing a vehicle sitting nearby called an Amphibicopter,' David takes the controls, and manages to release Joe from the clutches of the officers. Joe gets in and takes the controls, guiding them to 'Man-hattan.'
Their journey leads them to the flooded New York City where they find the Cybertronics building, on which sit statues of lions weeping water from their eyes. David enters a room, where he finds another mecha that looks just like him. However, feeling this duplicate could be planning to take his mother away from him, David destroys it in a jealous rage. It is then that Professor Hobby reveals his presence, telling David that he used Dr. Know to lead him 'home,' telling David that the Blue Fairy is only a myth. Hobby leaves David alone, to fetch the team members who designed him. David wanders around Hobby's office, finding the different mechanical items that were instrumental in his creation, as well as fully-boxed 'David' and 'Darlene' units for consumer purchase. The sight of them makes David feel even worse, in that his journey to become human has yielded no way for him to become human to regain his mother's love.
David makes his way outside the Cybertronics building, and then jumps off into the waters below. As he floats in the water he suddenly sees something glowing in the distance. Before he can move further, a claw from the Amphibicopter snares him, dragging him out of the water. Above the water, David tells Joe that he saw the Blue Fairy, and that she is down below. However, before Joe can help David, another Amphibicopter appears and captures Joe. Before he is pulled skyward, Joe activates the Amphibicopter for David to go underwater.
David and Teddy pilot the vehicle deep into the submerged city, finding themselves in the remnants of the Coney Island amusement park. David guides the craft to the park's Fairytale Land, and within a 'Pinocchio-themed' area, finds a statue of the Blue Fairy. However, maneuvering the craft causes a nearby Ferris wheel to collapse, trapping the Amphibicopter near the statue. David is not at all concerned, but is elated that he has finally found the Blue Fairy. He then begins to 'pray' to her, wishing to become a real boy.
Two thousand years pass in which the world has become blanketed in a new ice age, and humans have all but died out. Excavating the ice are evolved mechas of the future, trying to unearth and study the remnants of the culture and species that created them. An excavation team working amid the Coney Island amusement park comes across David and Teddy, frozen in the Amphibicopter.
Searching through David and Teddy's memories, they are amazed to find that he had once lived among humans. Using David and Teddy's memories, they concoct a fabricated reality of the Swinton's house, in which David meets a creation resembling the Blue Fairy. David wishes to be a real boy, and to see Monica again. The blue fairy explains that she cannot make him real, and that since 2,000 years have passed, she is no longer living. The blue fairy tells David they can bring back other humans, but David only wants Monica. Explaining that they need a hair sample or other human tissue, Teddy reveals the strands of hair that David had snipped from Monica's head. David demands that since he has Monica's hair, the blue fairy should now be able to bring her back. The Blue Fairy says that she can make this so, and David is taken to his room.
After some time, one of the future mechas comes to talk with David, concerning his 'wish' to have Monica brought back to life. The mecha explains that in the past the resurrection of humans have proven to be non-lasting, that any such 'resurrectees' would only live for one day. Even with this revelation, David still wishes to meet Monica again.
The future mechas grant him his wish, and the resurrected Monica and David, along with Teddy, spend an entire day together, doing all sorts of things. When it finally comes time for them to go to sleep, the resurrected Monica tells David that she loves him. With this knowledge, David himself also goes to sleep, content and happy at last.