Everyone petrified by the basilisk recovers, from Mrs. Norris on up to Hermione. Ginny recovers. Dumbledore dispels Harry's fears about whether he belongs in Gryffindor or Slytherin when he tells Harry that it is his choices that define him and not his abilities, and that Harry could not have wielded the sword of Gryffindor if he did not truly belong to that house. With Ron and Harry granted two-hundred points each for their adventure, Gryffindor wins the House Cup for the second year in a row. As a school treat, all final exams are cancelled (much to Hermione's dismay; she studied for nothing).
Dobby reveals he is the Malfoys' servant, and knowing their treachery, had been trying to protect Harry all year. Harry realizes Lucius Malfoy, Draco's father, slipped the diary into Ginny's cauldron when he encountered the Weasleys in a Diagon Alley bookshop. House elves can only be freed when their masters give them clothing; Harry tricks Malfoy into giving Dobby clothes by hiding Riddle's diary in his sock, remembering what Dobby had said on his birthday that his (Dobby's) owners would not even give him a sock, in fear of setting him free. Malfoy tosses the sock, still slimy from Harry's battle with the Basilisk, straight into Dobby's hands. Lucius Malfoy attempts to attack Harry when he realizes what Harry has made him do, but the grateful Dobby, no longer bound to obey the Malfoy family, intervenes and blasts Lucius with some magic of his own. A disheveled Lucius gathers himself and exits Hogwarts, declaring that Harry will soon meet the same end as his parents for his meddling.