Lord Voldemort ordered Nagini (his snake/Horcrux) to kill Snape in the Shrieking Shack (Chapter 32, Deathly Hallows). Voldemort believed Snape was the master of the Elder Wand and that killing him would transfer its allegiance.
Snape died giving Harry his memories—revealing his lifelong loyalty to Dumbledore and love for Lily Potter.