Why does the military intervene in the politics of some countries but remain under firm civilian control in others? The paper argues that the origins of military intervention in politics lie in a fundamental moral hazard problem associated with authoritarian repression. Dictators must deter those who are excluded from power from challenging them. When underlying, polity-wide conflict results in threats to the regime that take the particular form of mass, organized, and potentially violent opposition, the military is the only force capable of defeating them. The military exploits this pivotal position by demanding greater institutional autonomy as well as a say in policy, and it threatens to intervene if the civilian leadership departs from a subsequent compromise on these issues. A game-theoretic analysis of such contracting on violence implies that the likelihood of military intervention in politics should be greatest at intermediate levels of mass threats. Original, large-N data on military intervention support these claims.