Peter Parker is finding his double life increasingly difficult. Precariously struggling to balance his crime-fighting duties with the demands of his normal life, Peter often finds his personal life taking a back seat. He loses a job, faces financial difficulties, and struggles to maintain his physics studies at Columbia University. Moreover, he has become estranged from both love interest Mary Jane, who to Peter's disappointment is in a relationship, and best friend Harry Osborn who falsely accuses Spider-Man of murdering his father, and Aunt May is threatened with foreclosure.
Harry, now head of Oscorp's research division, has invested in the research of brilliant scientist Otto Octavius, Peter's idol. To perform a sustained fusion experiment, Octavius has developed a set of artificially intelligent mechanical arms, which are impervious to heat and magnetism. Though the experiment overloads and becomes unstable, Dr. Octavius refuses to halt it, with devastating results: his wife is killed; the neural inhibitor chip which prevented the advanced AI of the arms from influencing Octavius's own mind is destroyed; and the arms are fused to his spine. Unconscious, he is taken to a hospital to have the appendages removed, but the tentacles develop their own ability to move at will and brutally kill the surgeons, and Octavius escapes. Uncontrolled, the tentacles begin to corrupt Octavius' mind, playing on his vanity and ego, and he decides he must complete his experiment at any cost. J. Jonah Jameson names him "Doctor Octopus" or "Doc Ock". In an effort to finance his experiments, Doc Ock attempts to rob a bank where Peter Parker and his Aunt May happen to be present. After a short glitch in his powers, Spider-Man manages to recover and soon the two take their fight outside the bank, but Doc Ock takes Aunt May as a hostage. When Spider-Man rescues her, she revises her former opinion of him and realizes that he is a hero. Octavius escapes unharmed.
During a party, Peter learns that M.J. is planning to marry J. Jonah Jameson's son, John Jameson, an astronaut. He also gets into a physical altercation with Harry, who is drunk because Octavius' failed experiment left Oscorp bankrupt, over his loyalty to Spider-Man; shortly after he loses his powers while web-slinging across town. Meanwhile, Octavius rebuilds his experimental reactor. Peter questions if he could ever have what he "needs", a life as Peter Parker, which involves a vision of Uncle Ben, and resolves to give up being Spider-Man, to which J. Jonah Jameson is delighted, having been given the abandoned Spider-Man suit. Back home, after visiting Uncle Ben's grave, Aunt May is distressed by Peter's confession that he was somewhat responsible for his Uncle Ben's death. Aunt May and Peter reconcile, and she tells Peter of the hope that Spider-Man brings to others, in spite of what dreams he may have to sacrifice. Peter attempts to re-connect with Mary Jane, but she informs him it is too late. In the meantime, Doc Ock has completed rebuilding his reactor, and needs one final item: the tritium which fuels the reactor. He goes to Harry Osborn for it, dangling him over the edge of the Osborn mansion balcony when he refuses. Harry agrees to give Ock what he needs in exchange for capturing Spider-Man.
Mary Jane meets Peter in a coffee shop to ask if he still loves her, but Peter tells her that he does not. Doc Ock, having been advised by Harry that Peter was the key to finding Spider-Man, destroys the coffee shop. Peter regains his spider-sense at the right moment to throw Mary Jane and himself out of the way of a thrown taxi, but Doc Ock abducts Mary Jane in a plot to lure Spider-Man into a trap. Peter's powers fully return, and he dons his costume and engages Doc Ock in a battle, which starts off at the top of a bell tower and then on top of a train. During the battle, Octavius manages to destroy the brakes to the train, forcing Spider-Man to rescue the runaway train.
Spider-Man manages to stop the train before it can plunge over the end of the track, but at great physical exertion. He nearly falls, but the people in the train catch him and see him without his mask on. They agree to keep his identity a secret and try to protect him from Doc Ock, but his mechanical arms are too much for them. Weak from his exertions Spider-Man becomes dizzy and faints and he is captured by Doctor Octopus and delivered to Harry Osborn. Harry unmasks Spider-Man and is shocked to discover that his sworn enemy is his best friend. Spider-Man awakens and convinces Harry to reveal Octavius' whereabouts so he can rescue Mary Jane, learning that Octavius is rebuilding his machine and threatening the world. Spider-Man finds Doctor Octavius in an abandoned warehouse on a waterfront pier, where he's restarted his fusion experiment. After battling with Doc Ock, Spider-Man manages to stun the villain with an electric shock. Peter then reveals his true identity to Octavius and pleads with him to stop the machine. Returned to his senses by the shock and determined to end his doomsday experiment before it causes more harm, Octavius uses his mechanical arms to collapse the floor of the building, successfully drowning the device at the cost of his own life. Mary Jane sees Peter without his mask on, but Peter tells her they can never be together, as he will always have enemies.
Across town, Harry has visions of his father, the late Norman Osborn, in a hanging mirror. The illusion demands that his son kill Peter Parker to avenge his death. Harry refuses and hurls a dagger at the mirror, shattering it and revealing a secret room, containing the Green Goblin's war gear. At the end of the film, Mary Jane leaves her wedding and finds Peter in his apartment, telling him that she has decided to be with him despite the risks. She persuades Peter to finally let her in while accepting the need of his vows by letting him respond to a sudden call for help. She looks on in uncertainty as Spider-Man swings away.