Soon after the start of Harry's second session at Hogwarts, messages on the walls of the corridors say that the mythical Chamber of Secrets has been re-opened and that the "Heir of Slytherin" would kill all pupils whose parents are not both magical – which includes Hermione. At intervals various inhabitants of the school are found petrified in corridors. Meanwhile, Harry, Ron, and Hermione discover Moaning Myrtle, the ghost of a girl who was killed the last time the Chamber was opened, and who now haunts the girls' toilet in which she died. Myrtle shows Harry a diary bearing the name "Tom Marvolo Riddle". Although its pages are blank, it responds when Harry writes in it. Eventually the book shows him Hogwarts as it was 50 years ago, just after Myrtle's death. There he sees Tom Riddle, a pupil at the time, pin the blame for Myrtle's death on Hagrid, who was then 13 years old and already devoted to keeping dangerous magical creatures as pets.
Four months later, the diary is stolen, and shortly afterwards Hermione is petrified. However, she holds a note explaining that the culprit is a basilisk, a huge serpent whose gaze kills those who look into its eyes directly but only petrifies those who look into them by means of a reflecting surface, such as water or a mirror. Hermione concluded that the monster travels through the school's pipes and emerges through the toilet Myrtle haunts. As the attacks continue, Cornelius Fudge, the Minister for Magic, holds Hagrid in the wizards' prison as a precaution. Lucius Malfoy, a former supporter of Voldemort who claims to have reformed, then announces that the school's governors have suspended Dumbledore from the position of headmaster.
After Ron's younger sister Ginny is abducted into the Chamber, the staff insist that the Dark Arts teacher, Gilderoy Lockhart, should handle the situation. However, when Harry and Ron go to his office to tell him what they have discovered about the basilisk, Lockhart reveals that he is a fraud who took credit for the accomplishments of others and attempts to erase the boys' memories. Disarming Lockhart, they march him to Moaning Myrtle's toilet, where Harry opens the passage to the Chamber of Secrets. In the sewers under the school, Lockhart grabs Ron's wand and tries again to wipe the boys' memories – but Ron's wand had been damaged in an accident at the start of the school year and the spell backfires, inflicting total amnesia on Lockhart, collapsing part of the tunnel and separating Harry from Ron and Lockhart.
While Ron attempts to tunnel through the rubble, Harry enters the Chamber of Secrets, where Ginny lies beside the diary. As he examines her, Tom Riddle appears, looking exactly as he did 50 years ago, and explains that he is a memory stored in the diary. Ginny wrote in it about her adolescent hopes and fears, and Riddle won her confidence by appearing sympathetic, possessed her, and used her to open the Chamber. Riddle also reveals that he is Voldemort as a boy. He further explains that he learned from Ginny who Harry was and about his own deeds as Voldemort. When Ginny realised that she had been responsible for the attacks, she attempted to throw the diary away, and it came into Harry's possession. Riddle then releases the basilisk to kill Harry. Dumbledore's pet phoenix, Fawkes, brings a magnificent sword wrapped in the Sorting Hat. Harry uses the sword to kill the basilisk – but only after being bitten by the creature's venomous fangs, one of which breaks off. As Riddle gloats over the dying Harry, Fawkes cures him with its tears. Harry stabs the diary with the broken fang, and Riddle screams and vanishes. Ginny revives after Riddle's disappearance and they return to Ron, who is still watching over the memory-wiped Lockhart. Fawkes airlifts all four out of the tunnels.
Harry recounts the whole story to Dumbledore, who has been reinstated. The headmaster revokes his threat to expel the boys if they broke more rules and gives them special awards for services to the school. When Harry mentions his earlier fears that he was the Heir of Slytherin, Dumbledore says that Harry chose Gryffindor House, and only a true member of that House could have used Godric Gryffindor's sword to kill the basilisk. Lucius Malfoy bursts in, and Harry accuses him of slipping the diary into one of Ginny's books while all the pupils were shopping for school books. Malfoy replies, "Prove it." Finally, all of the basilisk's petrified victims are revived by a potion, the preparation of which has taken several months.