This term describes an event, situation or decision that is
undesired but
unavoidable.
For example, many people consider taxes levied by the government to be a necessary evil: while no one likes having money taken from his wages, taxes are needed to fund the government and its services. The term can also apply to non-compulsory situations -- for example, you may dislike mobile phones, but at the same time must be reachable when you are away from home due to family or work related obligations; the phone is not truly necessary, however it is an apt solution for the particular problem.
See the lesser of two evils.