Arab traders were active in Tanganyika's coastal region by the eighth century. By the twelfth century, traders from India had arrived. In 1506, the Portuguese claimed control of the coastal region, although they neither colonized nor explored it. By the early eighteenth century indigenous coastal dwellers, with the assistance of Omani Arabs, had driven the Portuguese from the area. The Omani Sultan, Seyyid Said, claimed the coastal region for himself and eventually moved his capital to Zanzibar in 1841.
The mid-nineteenth century saw the arrival of European explorers. Germans reached Mount Kilimanjaro in the 1840s, and the British reached Lake Tanganyika by 1857. Colonial rule soon followed. The Germans contrived to bring African societies under their "protection" by negotiating fraudulent treaties with illegitimate African leaders. In 1886 and 1890, Anglo-German agreements were reached stipulating specific spheres of influence for each nation. The United Kingdom took control over Zanzibar and Germany over Tanganyika. Germany's defeat in World War I spelled the end of its African colonial empire and Tanganyika was passed to the United Kingdom under a League of Nations mandate. After World War II, Tanganyika became a United Nations trust territory under British control. The first Tanganyikan political party was formed in 1954 by Julius K. Nyerere. The Tanganyika African National Union (TANU) and Nyerere were instrumental in guiding Tanganyika to independence. In May 1961, the country became autonomous with Nyerere as prime minister under a new Constitution. Full independence came in December 1961. Nyerere was elected president of Tanganyika when the country became a republic within the Commonwealth in 1962.
Zanzibar, the other part of the United Republic of Tanzania, had a stormier path to independence than the mainland. British interests became established in Zanzibar for both commercial purposes and in an attempt to end the slave trade. The British reached an agreement with the Sultan in 1822 to end the slave trade, but it was more than 50 years until it finally came to an end. The Anglo-German agreement in 1890 made Zanzibar a British protectorate and the British incorporated the sultan into their colonial administration. The British created a strict racial hierarchy on the islands with Europeans on top and Arabs favored over Africans. According to the British, Zanzibar was an Arab state. In December 1963, Zanzibar became an independent sultanate; in January 1964, the sultan was deposed by an armed uprising of members of the African nationalist Afro Shirazi Party and a republic was proclaimed. In April 1964, the Zanzibari government signed an Act of Union with Tanganyika and the United Republic was formed.
The political history of the Tanzania has been largely shaped by the political stature of Tanganyika's first president, Julius Nyerere. Considered the father of the country, Nyerere was president of Tanzania from 1962 to 1985. Under his leadership the country embarked on a course of democracy within a one-party state. TANU was the only recognized political party and all candidates for any office were TANU members. This, however, did not preclude sometimes hotly contested races among several candidates from within the party. In 1977, TANU, under Nyerere's leadership, merged with the Afro Shirazi Party, the sole political party on Zanzibar, to form the Chama cha Mapinduzi (CCM— Revolutionary Party). Nyerere implemented a sweeping economic reorganization known as ujaama , a system
intended to produce a uniquely African form of socialism. State control of everything from agricultural collectivization to transportation and utility services was initiated. Widely viewed as a failure, the system nevertheless remained in place until the 1980s when Nyerere's hand-picked successor, Ali Hasan Mwinyi, began the slow process of dismantling ujaama .
The Constitution of Tanzania, as adopted in 1977 and subsequently amended, articulates the structure of government. The president is head of state and head of government, and is elected to no more than two five-year terms. Universal suffrage is granted at age 18. The National Assembly is made of 274 legislators. There are 232 who are elected to five-year terms by popular vote. The president then nominates the remaining 42 members of Parliament. The Union of Tanzania is a carefully structured balance of interests, with guarantees of Zanzibari representation in the National Assembly and at the executive level. Zanzibar continues to elect its own president and House of Representatives, which have authority over the two islands' internal affairs. In 1992, the move toward a multiparty state was initiated. The 1995 elections were the first multiparty elections held in Tanzania since the early 1960s, marking the rise of Benjamin Mkapa to the presidency of the Republic.
In August 1998 the U.S. embassy in Dar es Salaam was the target of a terrorist bombing. Twelve people, all Tanzanians, were killed in the incident alleged to be linked to the international terrorist, Osama bin Laden.