What makes some elections violent?

In elections around the world, violence is common. When do leaders exercise restraint in the face of a serious challenger, and when do they resort to electoral violence?