For much of its history Gao was an important commercial centre involved in the trans-Saharan trade. In the 9th century external Arabic writers described Gao as an important regional power, and by the end of the 10th century, the local ruler was said to be a Muslim. Towards the end of the 13th century Gao became part of the Mali Empire, but in first half of the 15th century the town regained its independence and with the conquests of Sunni Ali (ruled 1464–1492) it became the capital of the Songhai Empire. The Empire collapsed after the Moroccan invasion in 1591 and the invaders chose to make Timbuktu their capital. By the time of Heinrich Barth's visit in 1854, Gao had declined to become an impoverished village with 300 huts constructed from matting. In 2009, the urban commune had a population of 86,633.