Dobby the house-elf died during the Battle of Hogwarts while protecting Harry Potter.
In Harry Potter and the Deathly Hallows, Dobby disarms Bellatrix Lestrange as she tries to kill Harry. This allows Harry to disarm Lucius Malfoy, who loses control of his wand and accidentally kills Bellatrix. Dobby is fatally struck by Bellatrix's curse but dies a hero.
The film adaptation portrays this similarly, with Dobby taking the curse meant for Harry and dying in his arms.