In Bellatrix's vault, Harry discovers that the Horcrux is Helga Hufflepuff's cup. He retrieves it, but Griphook snatches the sword of Godric Gryffindor and abandons the trio, leaving them cornered by security. The three release the dragon guardian and flee on its back. Harry sees a vision of Voldemort killing goblins, including Griphook, and learns Voldemort is aware of the theft. Harry also realises there is a Horcrux at Hogwarts connected to Rowena Ravenclaw. The trio apparate into Hogsmeade, where Aberforth Dumbledore instructs the portrait of his deceased younger sister, Ariana, to fetch Neville Longbottom, who leads the trio through a secret passageway into Hogwarts.
Snape hears of Harry's return and warns staff and students of punishment for aiding Harry. Harry confronts Snape, who flees after Minerva McGonagall challenges him to a duel. McGonagall gathers the Hogwarts community for battle. At Luna Lovegood's insistence, Harry speaks to Helena Ravenclaw's ghost, who reveals that Voldemort performed "dark magic" on her mother's diadem, which is in the Room of Requirement. In the Chamber of Secrets, Ron encourages Hermione to destroy the Horcrux cup with a Basilisk fang. Afterward, the two share a passionate kiss. In the Room of Requirement, Draco, Gregory Goyle and Blaise Zabini attack Harry, but Ron and Hermione intervene. Goyle casts a Fiendfyre curse and, unable to control it, is burned to death while Harry and his friends save Malfoy and Zabini. Harry stabs the diadem with the Basilisk fang, and Ron kicks it into the Room of Requirement, where it is destroyed. As Voldemort's forces attack, Harry, seeing into Voldemort's mind, realises that Voldemort's snake Nagini is the final Horcrux. After entering the boathouse, the trio witness Voldemort telling Snape that the Elder Wand cannot serve Voldemort until Snape dies; he then orders Nagini to kill Snape. Before dying, Snape tells Harry to take his memories to the Pensieve. In the chaos at Hogwarts, Fred, Lupin, and Tonks have been killed.
Harry learns from Snape's memories that Snape loved Harry's late mother, Lily, but despised his father, James, who had bullied him. Following her death, Snape worked secretly with Dumbledore to protect Harry from Voldemort because of his deep feelings for Lily. Harry also learns that Dumbledore's death at Snape's hands was planned between them, and that the Patronus doe he saw in the woods that led him to the sword had been conjured by Snape. Harry discovers that he himself became a Horcrux when Voldemort originally failed to kill him and that Harry must die to destroy the piece of Voldemort's soul within him. Harry goes to die at the hands of Voldemort in the Forbidden Forest. He briefly speaks to his dead loved ones before facing Voldemort. Voldemort casts the Killing Curse upon Harry, who finds himself in limbo, where Dumbledore's spirit meets him and explains that the part of Voldemort within Harry was killed by Voldemort's own curse. Due to Voldemort killing the Horcrux inside Harry, he is able to return to his body, determined to defeat Voldemort once and for all.
Voldemort announces Harry's apparent death to everyone at Hogwarts and says anyone who defies him will be killed. Neville stands up to Voldemort and makes a dramatic speech, stating that Harry will live on in their hearts. Harry reveals he is still alive and duels with Voldemort throughout the castle. A general battle begins as a defiant Neville draws the Sword of Gryffindor from the Sorting Hat and decapitates Nagini, leaving Voldemort mortal. Molly Weasley watches her daughter nearly get killed by Bellatrix during a duel and then kills Bellatrix. The final stand of Harry and Voldemort's fight is Harry's Disarming Charm rebounding Voldemort's own Killing Curse and obliterating him. After the battle, Harry explains to Ron and Hermione that the Elder Wand recognised him as its true master because he had disarmed Draco, who earlier had disarmed its previous owner, Dumbledore, which then explains why the wand didn't kill Harry in his final battle with Voldemort. Harry snaps the Elder Wand, rejecting its power.
Nineteen years later, Harry and Ginny Potter and Ron and Hermione Weasley, along with Draco and his wife Astoria Malfoy, proudly watch their own children leaving for Hogwarts from King's Cross station.