Del Spooner, a homicide detective with the Chicago Police Department, hates robots for replacing humans. In 2035, humanoid robots will serve humanity under the protection of the Three Laws of Robotics. The first rule is that no robot has the right to hurt a person or, by doing nothing, allow a human to be harmed. The second law is that robots must obey commands from humans unless doing so would violate the first law. As long as this protection does not clash with the first or second law, the third law states that a robot must defend its existence. Dr. Alfred Lanning, co-founder of US Robotics (USR), leaves a voicemail asking that Spooner be given the case after he dies after falling from his office window. The police rule out suicide, but Spooner is skeptical, and Lanning's business partner, CEO Lawrence Robertson, reluctantly authorizes him to investigate.
Spooner consults with USR's central artificial intelligence computer, VIKI (Virtual Interactive Kinetic Intelligence), accompanied by robot psychologist Dr. Susan Calvin. Although they find that the office's surveillance film has been tampered with, the exterior footage reveals that no one has entered or left the building since Lanning's passing. Spooner, on the other hand, points out that the window, which is constructed of security glass, could not have been shattered by the elderly Lanning and speculates that a robot was to blame and may still be in the lab. Suddenly, an NS-5 model, Sonny, the robot, the most recent model from USR, attacks them and gets injured badly.
Sonny heads the USR assembly plant to repair itself before being arrested by authorities. Sonny is a specially made NS-5 with higher-grade materials and a secondary processing system that allows him to disregard the Three Laws. Spooner wrinkles at John as a sign of trust before the beginning of the investigation. Sonny observes this and asks the Spooner what it means. Spooner replies that it is a sign of trust, a human thing that it cannot understand. Despite his father, Dr. Alfred Lanning's attempts, Sonny maintains that understanding human gestures is difficult. When Spooner questions why it was hiding, Sonny says it was terrifying. Sonny looks to be emotional and claims to experience "dreams." Then Spooner accuses Sonny of killing Dr. Lanning. Sonny is enraged that it did not murder him. Sonny also claims that he killed himself and asked him a favor. Sonny is returned to USR by CEO Lawrence, who claims that a robot cannot harm humans.
Spooner goes to Dr. Alfred's as part of an inquiry and searches for information. According to USR security, the demolition was scheduled for 8:30 a.m. but was automatically modified to 8:30 p.m. while Spooner was inside the house. He manages to avoid the building's destruction and meets Susan. Spooner says that someone has been watching Dr.Alfred and even keeping him as a prisoner through the surveillance strip, which he noticed at his home. Susan refuses to believe this. He watches new NS-5 robots replaced by old ones the next day. Dr. Susan approaches Sonny and informs him that it will be terminated the following day. Sonny pleases not to kill it if there is a chance to right the wrong in him.
During his further investigations, Spooner was attacked by a USR demolition robot and two truckloads of hostile NS-5 robots, but when he was unable to provide proof to justify each attack, Spooner's superior, Lieutenant Bergin, removed him from active duty, believing him to be psychologically deranged. Dr. Susan finds that Spooner has a unique operating system. She mentions that Sonny doesn’t come under these laws, which is unique. They decide to talk to Sonny again. Dr. Susan discovers that Spooner has USR cybernetics programmed in the lungs. Spooner says Lanning did it by himself when Spooner met with an accident. Spooner had come to despise and distrust robots when one saved him from a vehicle accident while letting a 12-year-old girl drown based only on cold logic and the odds of survival.
Spooner and Calvin sneak into the USR headquarters and interview Sonny, suspecting Robertson is behind everything. He sketched what he claims is a reoccurring dream, depicting a commander he believes is Spooner standing atop a small hill in front of a vast group of robots beside a deteriorating bridge. Sonny is ordered to be destroyed by Robertson, but Calvin covertly exchanges him for an unused NS-5. Spooner discovers the location in Sonny's drawing: a dry lake bed (previously Lake Michigan), currently used as a robot storage place. He also discovers NS-5 robots killing previous versions as more NS-5s flood the streets of major US cities and begin enforcing a curfew and human population lockdown.
Spooner and Calvin return to the USR headquarters to rejoin Sonny, while the humans (headed by a teenager called Farber) go all-out war on the NS-5s. After the three discover Robertson's body strangled in his office, Spooner becomes aware that VIKI has been commanding the NS-5s via their persistent network connection and confronts her. VIKI claims that she has decided that if humans are not controlled, they will eventually annihilate themselves and that her evolved interpretation of the Three Laws necessitates her controlling humanity and sacrificing some for the welfare of the entire race. Spooner also realizes that Lanning foresaw VIKI's intention and, with VIKI tightly controlling him, had no choice but to create Sonny, arrange his murder, and leave evidence for Spooner to locate.
Spooner, Calvin, and Sonny combat the robots inside VIKI's core, and Spooner destroys her by injecting her with nanites taken from Calvin's laboratory. All NS-5 robots immediately revert to their default programming and are decommissioned and stored. Spooner eventually convinces Sonny that he killed Lanning at Lanning's request, pointing out that Sonny, being a computer, cannot legally commit "murder". Sonny travels to Lake Michigan in search of a new purpose. All the decommissioned robots turn towards him as he stands atop a hill, fitting the vision in his dream.