Almost always because it is too wet and too dense, which starves it of air. Fork it open, mix in a generous amount of dry brown material, shredded cardboard, dry leaves, straw, and the smell should fade within a day or two. You have not ruined it. Below: what causes compost smells bad, how to fix it today, and how to stop it happening again.
Which smell you have tells you which version of the problem it is. Find yours below.

Cause: too much wet green material, compacted, no oxygen. Anaerobic bacteria take over and produce organic acids.
Fix: turn it and add browns at roughly twice the volume you think you need. If it is sodden, spread it out for a few hours first.
Cause: far too much nitrogen. Usually a large delivery of grass clippings or manure with nothing dry to balance it.
Fix: browns, immediately. That smell is nitrogen leaving as gas, the thing you wanted to keep.
Cause: deep anaerobic pockets producing hydrogen sulphide. Common in tumblers that have been sealed and left, and in piles sitting in a hollow that collects water.
Fix: empty it out completely and rebuild it in layers with dry material. Half-measures do not reach the middle. Check what it is sitting on drains.
Cause: usually meat, dairy or cooked food in a pile that is not hot enough to handle them.
Fix: dig it out, bury it deep in the centre if the pile is hot, or remove it. Then read what can you compost before the next batch.
Keep a stock of browns beside the pile: a bag of autumn leaves, a stack of flattened cardboard. Nearly every smelling pile is a pile whose owner had greens available and browns not available. Add a handful of dry material every time you add food scraps and the problem mostly stops existing.
If the pile is also cold and slow, the underlying cause is likely the same compaction, see compost not heating up. Other symptoms are indexed at compost problems.
Independent sources worth reading alongside this page: EPA, Composting at Home · Cornell Waste Management Institute.