Throughout the six previous novels in the Harry Potter series, the main character, Harry Potter, has struggled with the inherent difficulties of adolescence along with being a famous wizard. When Harry was a baby, Lord Voldemort, a powerful evil wizard, murdered Harry's parents but mysteriously vanished after attempting to kill Harry. This results in Harry's immediate fame, and his being placed in the care of his muggle, or non-magical, relatives Aunt Petunia and Uncle Vernon.
Harry re-enters the wizarding world at age 11, enrolling in the Hogwarts School of Witchcraft and Wizardry. He makes friends with Ron Weasley and Hermione Granger, and is soon confronted by Lord Voldemort, who is trying to regain power (and a body). Returning to school after summer break, there are several attacks on students after the legendary "Chamber of Secrets" is thought to be opened. Harry ends the attacks by killing a Basilisk and defeating Lord Voldemort's "memory" stored in an enchanted diary. The following year, Harry hears that he has been targeted by escaped murderer Sirius Black. Despite stringent security measures at Hogwarts, Harry is confronted by Black at the end of his third year of schooling and Harry learns that Black was framed and is his godfather. Harry's fourth year of school sees him entered in a dangerous magical competition called the Triwizard Tournament. At the conclusion of the Tournament, Harry witnesses the return of Lord Voldemort to full strength. When the next school year begins, the Ministry of Magic appoints Dolores Umbridge as the new High Inquisitor of Hogwarts. After forming an underground student group in opposition to Umbridge, Harry and several of his friends face off against Voldemort's Death Eaters, a group of Dark witches and wizards, and narrowly defeat them. In Harry's sixth year of school, he learns that Voldemort has been using Horcruxes to become immortal. Horcruxes are fragments of the soul that are placed within an object so that when the body dies, a part of the soul remains and the person can be regenerated or resurrected. However, the destruction of the creator's body leaves the wizard or witch in a state of half-life, without corporeal form. When returning from a mission to discover a Horcrux, Professor Dumbledore, the Headmaster of the school and Harry's mentor, is murdered by Severus Snape, a teacher at the school with whom Harry is consistently at odds and who Harry has suspected of being a Death Eater. At the conclusion of the book, Harry pledges not to return to school the following year and to search for Horcruxes instead.
Following Dumbledore's death, Voldemort has completed his ascension to power and gains control of the Ministry of Magic. Harry, Ron, and Hermione drop out of school to find and destroy Voldemort's remaining Horcruxes. They isolate themselves to ensure the safety of their family and friends. They do not have much knowledge about the remaining Horcruxes except the possibility that two of them are objects that belonged to Hogwarts founders Rowena Ravenclaw and Helga Hufflepuff, and that the third is Nagini, Voldemort's snake familiar. The locations of the two founders' objects are unknown, and Nagini is presumed to be with Voldemort himself. As they search for the Horcruxes, the trio learn details about Dumbledore's past, as well as Snape's true motives.
The trio recovers the first of Voldemort's Horcruxes, Salazar Slytherin's locket, by infiltrating the Ministry of Magic. They recover the Sword of Godric Gryffindor; it is one of a few objects that can be used to destroy Horcruxes (being dipped in Basilisk venom), and they use it to destroy the locket. In their travels the trio comes across a strange symbol, which an eccentric wizard named Xenophilius Lovegood (father of Luna) tells them represents the mythical Deathly Hallows. The Hallows are revealed to be three sacred objects: the Resurrection Stone, a stone with the power to recall the dead to the world of the living; the Elder Wand, an unbeatable wand; and an infallible Invisibility Cloak. Harry learns that Voldemort is seeking the Elder Wand, but is unaware of the Hallows and their significance. The trio decides that discovering Voldemort's Horcruxes is more important than procuring the Hallows for themselves. They break into Bellatrix Lestrange's vault at the Wizarding Bank Gringotts to recover another Horcrux, the cup of Helga Hufflepuff. Harry learns that another Horcrux is hidden in Hogwarts, and Harry, Ron, and Hermione enter the school. They find this Horcrux, the Diadem of Ravenclaw, and successfully destroy the cup and the diadem.
The book culminates in the Battle of Hogwarts. Harry, Ron, and Hermione, in conjunction with students and members of the wizarding world opposed to the rise of Voldemort, defend Hogwarts from Voldemort, his Death Eaters, and various magical creatures. Several major characters are killed in the first wave of the battle. Harry discovers that Voldemort inadvertently made Harry a Horcrux when he attacked him as a baby, and that he will have to die to destroy Voldemort. Harry surrenders himself to Voldemort, who attacks Harry with the Killing Curse, sending Harry to a sort of Limbo between life and death. There, Harry meets Dumbledore who explains that because Voldemort used Harry's blood to regain his full strength, Harry is protected from any harm that Voldemort could commit against him, meaning that the Horcrux inside Harry is destroyed, but Harry can return to his body despite being hit by the Killing Curse. Harry then returns to his body, the battle resumes, and after the last remaining Horcrux is destroyed, Harry is able to defeat Voldemort.
Nineteen years later, Harry and Ginny Weasley are married and have three children: James Sirius, Albus Severus, and Lily Luna. Ron married Hermione and has two children, Rose and Hugo. The families meet at King's Cross station, where a nervous Albus is departing for his first year at Hogwarts. Harry's godson, Teddy Lupin, is found kissing Victoire Weasley (Bill and Fleur's daughter) in a train carriage. Harry sees Draco Malfoy and his wife Astoria Greengrass (revealed on Rowling's website behind the door) with their son, Scorpius. Neville Longbottom is now the Hogwarts Herbology professor and remains friends with the two families. Harry comforts Albus, who is worried he will be sorted into Slytherin, and tells his son that one of his two namesakes, Severus Snape, was a Slytherin and the bravest man he had ever met. He adds that the Sorting Hat takes one's choice into account, like it did for Harry. The book ends with these final words: "The scar had not pained Harry for nineteen years. All was well."