We show how in colonial Potosí (present-day Bolivia) social and political stability was achieved through the self-organization of society through the repetition of religious rituals. Our analysis shows that the population of Potosí develops over time a series of cycles of rituals and miracles as a response to social upheaval and natural disasters and that these cycles of religious performance become crucial mechanisms of cooperation among different ethnic and religious groups. Our methodology starts with a close reading and annotation of the Historia de Potosí by Bartolomé Arzans. Then, we model the religious cycles of miracles and rituals and store all social and cultural information about the cycles in a multirelational graph database. Finally, we perform graph analysis through traversals queries in order to establish facts concerning social networks, historical evolution of behaviors, types of participation of miraculous characters according to dates, parts of the city, ethnic groups, etc. It is also important to note that the religious activity at the group level gave native communities a way to participate in the social life. It also guaranteed that the city performed its role as producer of silver in the global economic structure of the Spanish empire. This case proves the importance of religion as a mechanism of stability and self-organization in periods of social or political turbulence. The multidisciplinary methodology combining traditional humanistic techniques with graph analysis shows a great potential for other sociological, historical, and literary problems.