State and religion, two of the oldest institutions known to mankind, have historically had a close relationship with each other, but the disestablishment of state religions has been one of the most drastic institutional transformations that has taken place in the modern era. We offer a systematic analysis of the development of secular states based on a political economy approach that is centered on the notion of legitimacy. Viewing religion as a legitimizing force for political leaders, we consider the factors affecting the cost and benefits of alternative sources of legitimacy, such as the differential abilities of religious and secular sources to legitimize political rulers and historical inertia that shaped the cost of monitoring legitimizing agents. To examine this argument empirically, we built a cross-national time-series dataset for the relationship between state and religion since the year 1000. We first use the data to examine the evolution of secularism over time and its variation across religious traditions. We then use regression analysis and an instrumental variables approach to identify the influences on the adoption of secular state, such as concentration in the religion market, religious differences between rulers and the general population, historical inertia of a state, and the prevailing political regime. We address endogeneity concerns regarding the relationship between religious concentration and state secularity by exploiting variation among territories in their geographic distance to religious "capitals" of the world as an instrument.