Herat is one of the oldest mosques in the country, believed to have been first built under the Ghurids in the 12th century. During this period, known as the Islamic Golden Age, Afghanistan became the second major center of learning in the Muslim world after Baghdad. After the Mongol invasion and destruction, the Timurids rebuilt the area and once again made it a center of Islamic learning. Shia Islam made its way to southern Afghanistan during the Safavid rule in the 16th century. Until Mir Wais Hotak liberated the Afghans in 1709, the Kandahar region of Afghanistan was often a battleground between the Shia Safavids and the Sunni Mughals. Conquest by Abdur Rahman Khan The first systematic employment of Islam as an instrument of state-building was initiated by King Abdur Rahman Khan (1880–1901) during his drive toward centralization. He decreed that all laws must comply with Islamic law and thus elevated the Shariah over customary laws embodied in the Pashtunwali. The ulama were enlisted to legitimize and sanction his state efforts as well as his central authority. This enhanced the religious community on the one hand, but as they were increasingly inducted into the bureaucracy as servants of the state, the religious leadership was ultimately weakened. Many economic privileges enjoyed by religious personalities and institutions were restructured within the framework of the state; the propagation of learning, once the sole prerogative of the ulama, was closely supervised; and the Amir became the supreme arbiter of justice. Abdur Rahman Khan's successors continued and expanded his policies as they increased the momentum of secularization. Islam remained central to interactions, but the religious establishment remained essentially non-political, functioning as a moral rather than a political influence. Nevertheless, Islam asserted itself in times of national crisis. Moreover, when the religious leadership considered themselves severely threatened, charismatic religious personalities periodically employed Islam to rally disparate groups in opposition to the state. They rose up on several occasions against King Amanullah Shah (1919–1929), for example, in protest against reforms they believed to be western intrusions inimical to Islam. Subsequent rulers, mindful of traditional attitudes antithetical to secularization, were careful to underline the compatibility of Islam with modernization. Even so, and despite its pivotal position within the society, which continued to draw no distinction between religion and state, the role of religion in state affairs continued to decline. The 1931 Constitution made Hanafi Shariah the state religion,