Near the end of Harry Potter and the Deathly Hallows, Voldemort orders his snake Nagini to kill Snape. As Snape lies dying, he passes Harry a set of memories tied to his protection of Harry, his conversations with Dumbledore, and his long-standing love for Harry's mother. When Harry later views these memories in the Pensieve, he's forced to realize that Snape had been protecting him all along and working as a spy for Dumbledore.