According to most accounts, Timbuktu was founded in the 12th century. Popular etymology of the name attributes it to the site where a slave named Buktou lived. It is located 15 km north of the bend in the Niger River in the arid borderlands of the Sahara. Timbuktu was in a good location to be an entrepôt of regional trade networks that brought salt mined in the Sahara to the south in exchange for gold, grain and other items which were sent north. Timbuktu also became an important site in the trans-Saharan trade that connected North and West Africa. Incorporated into the Mali Empire in the 14th century, the town welcomed several Muslim scholars who returned with its ruler Mansa Musa,(c 1280-c1337) from his pilgrimage (1324-1325) to Mecca. One of these was a Spanish architect who built the Grand Mosque (Djingerebeer) in Timbuktu. The wealth of Mali attracted other scholars to West Africa, and this helped to inaugurate the beginnings of a very serious engagement with the fullness of Islamic knowledge. The Mali Empire lost control of Timbuktu in 1433. It was brought under the power of the expanding Songhay Empire in 1468, when it was conquered by Sunni Ali Beer.
The city was never a seat of political power, nor the capital city of a large state. Instead, it was a port city on the southern shore of the Sahara desert. The tradition of Islamic scholarship that developed there was not beholden to a royal court or a state; instead, Muslim scholars were able to operate much more independently with less need to compromise with non-Muslim religious practice. The destruction of the Songhay Empire at the hands of a Moroccan invasion in 1591 did result in Timbuktu becoming the temporary seat of the Moroccan occupation and its successor state known as the Arma, but from the 17th century Timbuktu declined in political importance even as it continued to act as a commercial entrepot and site of Islamic scholarship. Conquered by the French in 1893, the city regained some of its luster as a provincial capital and garrison center. Since independence in 1960, tourism has played an important role in reshaping the city when the security situation allows it.