In 645 AD, the Kerman region was conquered by the Arabs and Arg-e-Bam probably suffered damage during the war. One of the Arab commanders established the Al Rasoul mosque, one of the first mosques built in Iran in the early Islamic era. In 656 AD, the Khawarij, a group of Muslims defeated by Ali, escaped to Kerman and Bam where they settled in the Arg-e-Bam. In 869 AD, Ya'qub ibn al-Layth al-Saffar who was fighting the Abbasids, defeated the Khawarij and took over Arg-e-Bam. It then became his permanent base camp. The name of Bam is mentioned for the first time by Islamic writers in the 10th century. According to these authors, Bam was then a well established market place surrounded by a wide agricultural area. The city was famous for its elegant and tasteful cotton fabrics, its supposedly impregnable fortress, its busy bazaars, and its palm trees.