The story of Kilwa begins around 960-1000 AD. According to legend, Ali ibn al-Hassan Shirazi was one of seven sons of a ruler of Shiraz, Persia, his mother an Abyssinian slave. Upon his father's death, Ali was driven out of his inheritance by his brothers. Setting sail out of Hormuz, Ali ibn al-Hassan, his household and a small group of followers first made their way to Mogadishu, the main commercial city of the East African coast. However, Ali failed to get along with the city's Somali elite and he was soon driven out of that city as well.
Steering down the African coast, Ali is said to have purchased the island of Kilwa from the local Bantu inhabitants. According to one chronicle (Strong, 1895), Kilwa was originally owned by a mainland Bantu king 'Almuli' and connected by a small land bridge to the mainland that appeared in low tide. The king agreed to sell it to Ali ibn al-Hassan for as much colored cloth as could cover the circumference of the island. But when the king later changed his mind, and tried to take it back, the Persians had dug up the land bridge, and Kilwa was now an island.
Rather than being a literal retelling of events, this legendary history serves to legitimize the dynasty through ties to Islam. According to Horton and Middleman, "the descent from a noble Islamic family and an Abyssinian (Ethiopian) slave 'explains' why the rulers were both black but also with royal Muslim descent; the giving of cloth to the ruler made him 'civilized' and so his daughter became marriageable."
Kilwa's fortuitous position made it a much better East African trade center than Mogadishu. It quickly began to attract many merchants and immigrants from further north, including Persia and Arabia. In just a few years, the city was big enough to establish a satellite settlement at nearby Mafia Island.
Kilwa's emergence as a commercial center challenged the dominance once held by Mogadishu over the East African coast. Suleiman Hassan, the ninth successor of Ali (and 12th ruler of Kilwa, c. 1178-1195), wrested control of the southerly city of Sofala. Wealthy Sofala was the principal entrepot for the gold and ivory trade with Great Zimbabwe and Monomatapa in the interior. The acquisition of Sofala brought a windfall of gold revenues to the Kilwa Sultans, which allowed them to finance their expansion and extend their powers all along the East African coast.
At the zenith of its power in the 15th century, the Kilwa Sultanate owned or claimed overlordship over the mainland cities of Malindi, Inhambane and Sofala and the island-states of Mombassa, Pemba, Zanzibar, Mafia, Comoro and Mozambique (plus numerous smaller places) - essentially what is now often referred to as the "Swahili Coast".
Kilwa also claimed lordship across the channel over the myriad of small trading posts scattered on the coast of Madagascar (then known by its Arabic name of Island of the Moon). To the north, Kilwa's power was checked by the independent Somali city-states of Barawa (a self-ruling aristocratic republic) and Mogadishu (the once-dominant city, Kilwa's main rival). To the south, Kilwa's reach extended as far as Cape Correntes, below which merchant ships did not usually dare sail.
While a single figure, the Sultan of Kilwa, stood at the top of the hierarchy, the Kilwa Sultanate was not a centralized state. It was more a confederation of commercial cities, each with its own internal elite, merchant communities and trade connections. The Sultan might appoint a governor or overseer, but even his authority was not consistent - in some places (e.g. outposts like Mozambique Island) he was a true governor in the Sultan's name, whereas in more established cities like Sofala his powers were much more limited, more akin to an ambassador to the city, than its governor.