People have lived in Zanzibar for 20,000 years.
History proper starts when the islands became a base for traders voyaging between the African Great Lakes, the Arabian peninsula, and the Indian subcontinent.
Unguja offered a protected and defensible harbor, 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.
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, with a ruling Arab elite and a Bantu general population. Plantations were developed to grow spices; hence, the moniker of the Spice Islands.
Another major trade good was ivory, the tusks of elephants that were killed on the Tanganyika mainland – a practice that is still in place to this day.
The third pillar of the economy was slaves, which gave Zanzibar an important place in the Arab slave trade, the Indian Ocean equivalent of the better-known Triangular Trade. 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, control of Zanzibar came into the hands of the British Empire. Part of the political impetus for this was the movement for the abolition of the slave trade.
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, led to the Republic of Zanzibar and Pemba. That April, the republic merged with the mainland Tanganyika, or more accurately, was subsumed into Tanzania, of which Zanzibar remains a semi-autonomous region.