We investigate how nondemocratic regimes use the military and how this can lead to the emergence of military dictatorships. Nondemocratic regimes need the use of force in order to remain in power, but this creates a political moral hazard problem; a strong military may not simply work as an agent of the elite but may turn against them in order to create a regime more in line with their own objectives. The political moral hazard problem increases the cost of using repression in nondemocratic regimes and in particular, necessitates high wages and policy concessions to the military. When these concessions are not sufficient, the military can take action against a nondemocratic regime in order to create its own dictatorship. A more important consequence of the presence of a strong military is that once transition to democracy takes place, the military poses a coup threat against the nascent democratic regime until it is reformed. The anticipation that the military will be reformed in the future acts as an additional motivation for the military to undertake coups against democratic governments. We show that greater inequality makes the use of the military in nondemocratic regimes more likely and also makes it more difficult for democracies to prevent military coups. In addition, greater inequality also makes it more likely that nondemocratic regimes are unable to solve the political moral hazard problem and thus creates another channel for the emergence of military dictatorships. We also show that greater natural resource rents make military coups against democracies more likely, but have ambiguous effects on the political equilibrium in nondemocracies (because with abundant natural resources, repression becomes more valuable to the elite, but also more expensive to maintain because of the more severe political moral hazard that natural resources induce). Finally, we discuss how the national defense role of the military interacts with its involvement in domestic politics.