Self sacrifice for the greater good of a population is a very common theme in nature. For example, it's been found that programmed cell death (PCD) has direct evolutionary roots among single-celled protists. In multi-cellular animals, PCD makes plenty of sense - it is used during development to remove unneeded tissues and create a correct body shape (body cavities, slits between eyelids, etc.) or to remove mutated/infected/damaged cells. For single-celled organisms, it is literally suicide, which is somewhat less obviously useful.
Turns out that stopping the progress of a viral infection by self-destruction is as valid in a population of protists as it is in an animal, for example. Or that "voluntarily" culling the population numbers when it's getting too crowded is a good idea so that at least some individuals survive instead of forcing everyone to starve. Here's a paper with some specific examples and speculation: http://www.sciencedirect.com/science/article/pii/S0167488908000384