According to medieval Arabic sources, the city of Ganja was founded in 859–60 by Muhammad ibn Khalid ibn Yazid ibn Mazyad, the Arab governor of the region in the reign of the caliph al-Mutawakkil, and so-called because of a treasure unearthed there. According to the legend, the Arab governor had a dream where a voice told him that there was a treasure hidden under one of the three hills around the area where he camped. The voice told him to unearth it and use the money to found a city. He did so and informed the caliph about the money and the city. Caliph made Muhammad the hereditary governor of the city on a condition that he would give the money he found to the caliph.