People have lived in Zanzibar for 20,000 years. The earliest written accounts of Zanzibar began when the islands became a base for traders voyaging between the African Great Lakes, the Somali Peninsula, the Arabian Peninsula, Iran, and the Indian subcontinent. Unguja offered a protected and defensible harbour, so although the archipelago had few products of value, Omanis and Yemenis settled in what became Zanzibar City (Stone Town) as a convenient point from which to trade with towns on the Swahili Coast. They established garrisons on the islands and built the first mosques in the African Great Lakes Region.

During the Age of Exploration, the Portuguese Empire was the first European power to gain control of Zanzibar, and kept it for nearly 200 years. In 1698, Zanzibar fell under the control of the Sultanate of Oman, which developed an economy of trade and cash crops, and an Arab elite that ruled over the Bantu general population. Plantations were developed to grow spices; hence, the moniker of the Spice Islands (a name also used for the Dutch colony the Moluccas, now part of Indonesia). Another major trade good was ivory, the tusks of elephants that were killed on the Tanganyika mainland. This practice continues in the 21st century.

The third pillar of the economy was slaves, which gave the Zanzibar slave trade an important place in the Indian Ocean slave trade. This was the Indian Ocean equivalent of the better-known Triangular Trade across the Atlantic Ocean. The Omani Sultan of Zanzibar controlled a substantial portion of the African Great Lakes coast, known as Zanj, as well as extensive inland trading routes.

Sometimes gradually, sometimes by fits and starts, the British Empire gained control of Zanzibar. In 1890, Zanzibar became a British protectorate. The death of one sultan and the succession of another of whom the British did not approve later led to the Anglo-Zanzibar War, also known as the shortest war in history.

The islands gained independence from Britain in December 1963 as a constitutional monarchy. A month later, the bloody Zanzibar Revolution, in which several thousand Arabs and Indians were killed and thousands more expelled and expropriated by the black majority, led to the formation of the People's Republic of Zanzibar. That April, the republic merged with the mainland Tanganyika, or more accurately, was subsumed into Tanzania, of which Zanzibar remains a semi-autonomous region. Recent decades in Zanzibar have seen political violence related to contested elections, with a major massacre taking place in 2001.

Prehistory

Zanzibar has been inhabited, perhaps not continuously, since the Paleolithic period. A 2005 excavation at Kuumbi Cave in southeastern Zanzibar found heavy-duty stone tools, which showed occupation of the site at least 22,000 years ago."Excavations at Kuumbi Cave on Zanzibar 2005", The African Archaeology Network: Research in Progress, Paul Sinclair (Uppsala University), Abdurahman Juma, Felix Chami, 2006 Archaeological discoveries of a limestone cave used radiocarbon techniques to prove more recent occupation, from around 2800 BC to the year 1 AD (Chami 2006). Traces of the communities include objects such as glass beads made in territories around the Indian Ocean. It is a suggestion of early trans-oceanic trade networks, although some writers have expressed doubt about this possibility.

No cave sites on Zanzibar have revealed pottery fragments used by the early and later Bantu farming and iron-working communities who lived on the islands (Zanzibar, Mafia) during the first millennium AD. On Zanzibar, the evidence for the later farming and iron-working communities dating from the mid-first millennium AD is much stronger and indicates the beginning of urbanism there when settlements were built with mud-timber structures (Juma 2004). This is somewhat earlier than the existing evidence for towns in other parts of the Swahili Coast, given as the 9th century AD. The first permanent residents of Zanzibar seem to have been the ancestors of the Hadimu and Tumbatu, who began arriving from the African Great Lakes mainland around 1000 AD. They had belonged to various Bantu ethnic groups from the mainland, and on Zanzibar they lived in small villages, not forming larger political units. Because they lacked central organization, they were easily subjugated by outsiders.

Early Trade Routes

Ancient pottery demonstrates existing trade routes with Zanzibar as far back as the ancient Sumer and Assyria. An ancient pendant discovered near Eshnunna, Mesopotamia, and dated ca. 2500–2400 BC., has been traced to copal imported from the Zanzibar region.

Traders from Arabia (mostly Yemen), the Persian Gulf region of Iran (especially Shiraz), and west India probably visited Zanzibar as early as the 1st century AD. During the Middle Ages, they were followed by Somalis with the emergence of Islam. Traders used the monsoon winds to sail across the Indian Ocean and landed at the sheltered harbor located on the site of present-day Zanzibar Town. Although the islands had few resources of interest to the traders, they offered a good location from which to make contact and trade with the towns of the Swahili Coast. A phase of urban development associated with the introduction of stone material to the construction industry of the African Great Lakes littoral began from the 10th century AD.

Traders began to settle in small numbers on Zanzibar in the late 11th or 12th century, intermarrying with the indigenous Africans. Eventually a hereditary ruler (known as the Mwenyi Mkuu or Jumbe), emerged among the Hadimu. A similar ruler, called the Sheha, was set up among the Tumbatu. Neither had much power, but they helped solidify the ethnic identity of their respective peoples.

The Yemeni built the earliest mosque in the Southern Hemisphere in Kizimkazi, the southernmost village in Unguja. A kufic inscription on its mihrab bears the date AH 500, i.e. 1107 AD.

Many villages consisted of lineage groups.

Portuguese rule Vasco da Gama's visit in 1499 marked the beginning of European influence. In 1503 or 1504, Zanzibar became part of the Portuguese Empire when Captain Ruy Lourenço Ravasco Marques landed and demanded and received tribute from the sultan, whose name goes unrecorded, in exchange for peace. Zanzibar remained a possession of Portugal for almost two centuries.

Zanzibar Sultanate

In 1698, Zanzibar fell under the control of the Sultan of Oman. The Portuguese were expelled and a lucrative trade in slaves (started decades earlier by the Portuguese to supply the West Indies), and ivory thrived, along with an expanding plantation economy centring on cloves. With an excellent harbor and no shortage of fresh water, Stone Town (capital of Zanzibar) became one of the largest and wealthiest cities in East Africa. Under Omani rule, all of the most fertile land was handed over to Omani aristocrats who enslaved the farmers who worked the land. Every year, hundreds of dhows would sail across the Indian Ocean from Arabia, Persia and India with the monsoon winds blowing in from the northeast, bringing iron, cloth, sugar and dates. When the monsoon winds shifted to the southwest in March or April, the traders would leave, with their ships packed full of tortoiseshell, copal, cloves, coir, coconuts, rice, ivory, and slaves.Petterson, Donald, Revolution In Zanzibar An American's Cold War Tale. New York: Westview, 2002. pp. 6–8. The Arabs established garrisons at Zanzibar, Pemba, and Kilwa. The height of Arab rule came during the reign of Sultan Seyyid Said (more fully, Sayyid Said bin Sultan al-Busaid), who in 1840 moved his capital from Muscat, Oman, to Stone Town. He established a ruling Arab elite and encouraged the development of clove plantations, using the island's slave labour. Zanzibar's commerce fell increasingly into the hands of traders from the Indian subcontinent, whom Said encouraged to settle on the island. After his death in 1856, his sons struggled over the succession. On April 6, 1861, Zanzibar and Oman were divided into two separate principalities. Sayyid Majid bin Said Al-Busaid (1834/5–1870), his sixth son, became the Sultan of Zanzibar, while the third son, Sayyid Thuwaini bin Said al-Said, became the Sultan of Oman.

Accounts by visitors to Zanzibar often emphasize the outward beauty of the place. The British explorer Richard Francis Burton described Zanzibar in 1856 as: "Earth, sea and sky, all seemed wrapped in a soft and sensuous repose...The sea of purist sapphire, which had not parted with its blue rays to the atmosphere...lay looking...under a blaze of sunshine which touched every object with a dull burnish of gold". Adding to the beauty were the gleaming white minarets of mosques and the sultan's palaces in Stone Town, making the city appear from the distance to Westerners as an "Orientalist" fantasy brought to life. Those who got closer described Stone Town as an extremely foul-smelling city that reeked of human and animal excrement, garbage and rotting corpses as garbage, sewage and bodies of animals and slaves were all left out in the open to rot. The British explorer Dr. David Livingstone when living in Stone Town in 1866 wrote in his diary: "The stench arising from a mile and a half or two square miles of exposed sea beach, which is the general depository of the filth of the town is quite horrible...It might be called Stinkabar rather than Zanzibar". Besides the pervasive foul odor of Stone Town, accounts by visitors described a city full of slaves on the brink of starvation and a place where cholera, malaria, and venereal diseases all flourished.

Of all the forms of economic activity on Zanzibar, slavery was the most profitable. All the blacks living on the island were Bantu people taken from the mainland. The slaves were brought to Zanzibar in dhows, where as many as possible were packed in with no regard for comfort or safety. Many did not survive the journey to Zanzibar. Upon reaching Zanzibar, the slaves were stripped completely naked, cleaned, had their bodies covered with coconut oil, and were forced to wear gold and silver bracelets bearing the name of the slave trader. At that point, the slaves were forced to march nude in a line down the streets of Stone Town, guarded by loyal slaves of the slavers carrying swords or spears, until someone would show interest in the procession.Petterson, pp. 23–24.

A captain from a ship owned by the East India Company who visited Zanzibar in 1811 and witnessed these marches wrote about how a buyer examined the slaves:

Every year, about 40,000–50,000 slaves were taken to Zanzibar. About a third went to work on clove and coconut plantations of Zanzibar and Pemba, while the rest were exported to Persia, Arabia, the Ottoman Empire and Egypt. Conditions on the plantations were so harsh that about 30% of the male slaves died every year, thus maintaining the demand for more slaves.

The Omani Arabs who ruled Zanzibar had, in the words of the American diplomat Donald K. Petterson, a "culture of violence", where brute force was the preferred solution to problems and outlandish cruelty was a virtue. (Petterson served in Zanzibar in the early 1960s and again after the revolution of 1964.) He later wrote that the ruling al-Busaid family was characterized by fratricidal quarrels as it was common for brother to murder brother, and this was typical of the Arab aristocracy, where it was acceptable for family members to murder one another to gain land, wealth, titles, and slaves. Visitors to Zanzibar often mentioned the "shocking brutality" which the Arab masters treated their slaves, who were so cowed into submission that there was never a slave revolt attempted on the island. The cruelty with which the Arab masters treated their slaves during the period of slavery on Zanzibar left behind a legacy of hate of the Arab minority, which exploded in the revolution of 1964.