The sixth novel in the series, Harry Potter and the Half-Blood Prince (2005), immediately precedes Harry Potter and the Deathly Hallows (2007).
It sets the stage for the finale: Dumbledore's death, the Horcrux hunt premise, Snape's Unbreakable Vow, and the romance arcs reaching boiling point.