“Dobby has no master! Dobby is a free elf, and Dobby has come to save Harry Potter and his friends!”
-- Dobby, just before the end (DH23)

The elf dies from a knife wound in rescuing Harry and his friends from Malfoy Mansion . Bellatrix had kept the short, silver knife underneath her robes before she threw it toward where Harry and his friends are vanishing (DH22). It hits Dobby in the chest. His last words were “Harry… Potter…” (DH23).
He is buried on the bluff near Shell Cottage (DH23).
Commentary
Notes
It is unclear whether Bellatrix's knife is magical or not, or why she cut Hermione's bindings with it rather than using a Severing Charm. It serves to establish that Bellatrix is carrying a knife that doesn't depend on her being able to Conjure a weapon with her wand, though, so that we know she has access to it whether or not she has her wand.
Dobby's final words are "Harry... Potter..." (DH23). This not only suggests Harry's importance to Dobby, it echoes the first words Dobby ever speaks to Harry: "Harry Potter!" (CS2). -BB
While still in the Malfoys' service, Dobby told Harry that "Dobby is used to death threats" and that he "gets them five times a day" at Malfoy Manor (CS10). He is actually killed by a member of the Malfoy household when he returns there as a free elf. -BB
Pensieve (Comments)
Tags: Bellatrix Remembrall deaths killing/killings murders violence