In December 1961, the East African state of Tanganyika achieved independence from the British, as a constitutional monarchy with Queen Elizabeth II as head of state. The country remained in the Commonwealth of Nations in June of the next year when the country became a republic. The British military had administered Tanganyika since the end of the First World War, before that it had been under the colonial control of the German East Africa Company. Prior to that, the Sultan of Oman ruled the area after he helped the indigenous population drive Portuguese colonists from the coast.
The Sultan of Oman also ruled the archipelago of Zanzibar from where he also forced the withdrawal of the Portuguese. In the nineteenth-century the islands became a British protectorate under the Sultan of Zanzibar. The British protection was part of their campaign against the slave trade, the islands’ ports being an important to the trade. In December 1963, Britain granted Zanzibar full independence as a constitutional monarchy under Sultan Jamshid bin Abdullah. Like Tanganyika, it soon became a republic, but only after a bloody revolution that cost thousands of lives.
See the U.S. Department of State’s website for information about Tanzania, including the history of its constituent parts.