Church and state have historically had an uneasy relationship, sometimes close allies, at others harsh adversaries, and at still others largely independent of one another. This paper develops an economic model of this relationship, where the state's objective is to maximize net tax revenue, while the church provides religious goods. Religious goods benefit the state in two ways: first, they provide utility to citizens, thus allowing the state to extract more taxes before running up against citizens' reservation utility (the point at which they would revolt), and second, they potentially provide legitimacy to the state, thereby lowering the costs of tax collection. If the latter effect is strong enough, the state may find it optimal to take control of the church, either to enhance its legitimizing effect, or to suppress its de-legitimizing effect. To evaluate the model's implications, we use recent cross-country data on the relationship between religion and state, including measures coded from the 2001, 2003, and 2005 International Religious Freedom reports. We also examine in more detail some of the paradigmatic cases indicated by the model, presenting various types of evidence from current and historical examples of each case.