Paleontologists Louis and Mary Leakey, working at Olduvai Gorge and elsewhere in northern Tanzania, uncovered fossil evidence that humanlike creatures inhabited the area at least as early as 3.7 million years ago. Excavations of Stone Age sites have revealed that the hunter-gatherers of the late Stone Age, known as Bushmen, were gradually displaced by successive waves of Cushitic, Bantu, and Nilotic peoples. By the 1st millennium AD , the Iron Age Urewe culture had developed along the western shore of Lake Victoria.
Arabs from the Persian Gulf area were engaged in trade along the Indian Ocean coast by the 9th century AD and by the 12th century had established trading posts on the mainland and the offshore islands. Intermarriage between the Arabs and coastal Bantu-speaking peoples resulted in the creation of the Swahili people and language. (Swahili literally means "of the coast.")
The first contacts of European nations with the East African coast were incidental to their quest for spices. In 1498, Vasco da Gama rounded the Cape of Good Hope, and thereafter the Portuguese established trading and supply posts on the East African coast for their ships on the way to India. Eventually, the Portuguese lost control of the sea routes, and in 1698, the Ya'aruba imam of the Ibahdi Arabs of Oman, Sa'if bin Sultan, expelled the Portuguese from every position that they held north of Mozambique. The Ibahdis of Oman long remained in at least nominal control of East Africa, and there was a lucrative trade in slaves and ivory.
Sayyid Sa'id bin Sultan (the ruler of Oman during 1806–56), above all others, must be regarded as the founder of modern Zanzibar. Sa'id first visited Zanzibar in 1828, and in 1840, he made the island his capital. A believer in free trade, he encouraged foreign merchants, including Indians, broke up Arab monopolies, and made commercial treaties with the United States and UK. Zanzibar is indebted to him most for his establishment of the clove tree. By the time he died in 1856, he had established a large, loosely held empire that included Oman and Zanzibar and the East African coast inland to the Great Lakes and the Congo. Zanzibar produced three-quarters of the world's clove supply on plantations worked by slaves from the mainland. British pressure forced the closing of the slave trade in 1876, although slavery itself was not abolished until 1897.
The rise of Zanzibar as a commercial center was largely do to its trading links to the interior. Many of the caravan routes that stretched across East Africa were pioneered by African mainland societies. For example, the Yao living around Lake Malawi supplied the southern Tanzania trading town of Kilwa with slaves and ivory. African societies that gained control over the trade routes enhanced their power and wealth. In northeast Tanzania, a powerful trading and military state emerged in the 1860s in Urambo. Its leader, Mirambo was an excellent military and commercial strategist. He challenged the position of coastal traders in the area as well as the leading states that were closely aligned to Zanzibar.
The first Europeans to explore the interior were the British Sir Richard Francis Burton and John Hanning Speke, who crossed the country in 1857 to search for the source of the Nile, which Speke discovered in 1858. In 1866, Sultan Majid of Zanzibar began building the coastal town of Dar es Salaam ("Haven of Peace"). In 1871, Scottish missionary and explorer David Livingstone had reached Ujiji when his whereabouts became unknown to the outside world; the Anglo-American explorer Henry Morton Stanley, commissioned by a US newspaper, located him there later in that year. Tanganyika (the name for the mainland prior to the 1964 union with Zanzibar) came under German influence in 1884–85, when Karl Peters concluded treaties with chiefs of the interior in order to secure a charter for his German East Africa Company.
In 1890, two treaties between Germany and Great Britain were signed: the first partitioned the territories on the mainland hitherto controlled by the sultan of Zanzibar; the second officially recognized Anglo-German spheres of influence, excluded Germany from the Upper Nile, and established a British protectorate over Zanzibar and Pemba. Tanganyika and Ruanda-Urundi (now Rwanda and Burundi) became recognized as German East Africa in 1891. As they occupied the interior, the German-led troops put down African opposition and uprisings. Intense military opposition to the European imperialism was led by Mirambo of the Nyamwezi in northwest Tanzania, by Mkwawa of the Hehe in southern highlands and by Meli of the Chagga around Kilimanjaro. However, the most bloody and intense opposition to German rule was the Maji-Maji war from 1905–1907. This war was inspired by Kinjekitile, a charismatic spiritual leader from southern Tanzania, succeeded in uniting a large number of African societies to fight the Germans. People who took Kinjekitile's medicine were told that the "white man's' bullets" could not harm them. After initial battlefield successes, the Germans initiated a scorched earth policy that eventually starved southern Tanzania into submission. During World War I, a small German force led by General Paul von Lettow-Vorbeck fought a long defensive guerrilla war against British armies, and much of Tanganyika was laid waste.
Beginning in 1920, the United Kingdom administered Tanganyika as a mandate of the League of Nations. A customs union was established with Kenya and Uganda, the cultivation of export crops was encouraged, and a system of indirect rule was instituted. A Legislative Council for Tanganyika was created in 1926, but not until 1945 were seats reserved for Africans. In 1946, Tanganyika became a UN trust territory. After 1954, the Tanganyika African National Union (TANU) petitioned the UN Trusteeship Council to put pressure on the UK administration to establish a timetable for independence. TANU-supported candidates won the elections of 1958–60 for the Legislative Council, and Julius Nyerere became chief minister in September 1960. On 9 December 1961, Tanganyika became an independent nation. On 9 December 1962, it was established as a republic, headed by Nyerere as president.
In Zanzibar, a Legislative Council with an elected element had been established in 1957. On 24 June 1963, a deeply divided Zanzibar attained internal self-government; it became completely independent on 10 December 1963 under the (ZNP) Zanzibar Nationalist Party. On 12 January 1964, however, the ZNP government was overthrown by African nationalists allowing ZNP's bitter rivals the ASP (Afro-Shirazi Party) to take power. The sultan, who had fled, was deposed, and Abeid Karume was installed as president. On 26 April 1964, Tanganyika merged with Zanzibar and became the United Republic of Tanganyika and Zanzibar, with Nyerere as president; in October, the name was changed to Tanzania. Karume, still president of Zanzibar and a vice president of Tanzania, was assassinated on 7 April 1972; his successor as head of the Zanzibar Revolutionary Council was Aboud Jumbe.
Under Nyerere, Tanzania became steadily more socialist. In international affairs, Tanzania became one of the strongest supporters of majority rule in southern Africa, backing liberation movements in Mozambique, Southern Rhodesia (now Zimbabwe) and South Africa. Growing differences between the East African Community's three members (Kenya, Tanzania, and Uganda) led to the breakup in 1977 of the 10-year-old group. Tanzania's border with Kenya remained closed until 1983. On 30 October 1978, Ugandan forces invaded Tanzania; Nyerere retaliated by sending 20,000 Tanzanian troops into Uganda. Ugandan President Idi Amin's forces were routed in April 1979, and former president Milton Obote, who had been living in exile in Tanzania, was returned to power. In 1982, Tanzanian troops helped put down an army mutiny in the Seychelles.
In 1980, Nyerere was reelected without opposition to his fifth and last term as president. During the early 1980s, Tanzania was plagued by poor economic performance, and there was a small, unsuccessful army mutiny against Nyerere in January 1983. There was also rising dissatisfaction in Zanzibar over the islands' political ties to the mainland; an attempt to overthrow Jumbe in June 1980 failed. In 1984, Jumbe and his colleagues, including his Chief Minister Seif Shariff Hamad, attempted to push for more autonomy for Zanzibar. As a result, Aboud Jumbe was pressured by the union government to resign his posts as vice president of Tanzania and president of Zanzibar in January 1984. His Chief Minister, Seif Shariff Hamad was detained. Ali Hassan Mwinyi, Jumbe's successor, was elected president of Zanzibar in April 1984. He was succeeded by Idris Abdul Wakil in October 1985. Mwinyi succeeded Nyerere as president of Tanzania in November 1985, following presidential and parliamentary elections, and was reelected in 1990. Mwinyi was identified with those in the ruling party, Chama Cha Mapinduzi (CCM), seeking greater political and economic liberalization, and in 1990 Nyerere resigned as chairman of the CCM. On October 14, 1999 Julius Nyerere died of leukemia. Idris Wakil, died shortly after on March 15, 2000.
Liberalization was not easy to attain. Except for religion, the CCM controlled almost all areas of social affairs. Party cells at work and in the community shadowed Tanzanians constantly. In February 1992, at an extraordinary national conference of CCM, delegates voted unanimously to introduce a multiparty system. On 17 June 1992, Mwinyi signed into law constitutional amendments that allowed new parties (with certain exceptions) to participate in elections. The first multi-party elections since the reinstitution of multi-party politics were local government elections held in 1994. In the elections the ruling party CCM soundly defeated the opposition parties. Despite strong government and CCM support for liberalization, the state is at least rhetorically committed to socialism as the concept of "socialism and self-reliance" is retained in article nine of the union constitution.
Rifts between the mainland (Tanganyika) and Zanzibar grew in the 1990s, often linked to the ongoing Christian-Muslim division. In December 1992, in violation of the constitution, the government in heavily Muslim Zanzibar covertly joined the Organization of Islamic Countries (OIC). In August 1993, parliament debated a motion calling for constitutional revisions to create a separate government for Tanganyika, to parallel the Zanzibar government. At that point, Zanzibar agreed to withdraw from the OIC and to allow Tanzanians from the mainland to visit without passports.
In April 1993, fundamentalist Muslims were arrested for attacking owners of pork butcheries in Dar es Salaam. Demonstrations at their trials led to more arrests and a government ban on the Council for the Propagation of the Koran. Around the same time the government also arrested an evangelist pastor named Christopher Mtikila who had formed a political party not recognized by the government. Mtikila a populist preacher accused the government of selling the country off to Arabs and Zanzibaris and his actions helped to heighten Christian-Muslim tensions. Mwinyi shuffled his cabinet several times in 1993 to balance Christian and Muslim interests. Later under the Mkapa regime, religious tensions became apparent again when Muslims protested over the arrest of a religious leader from the Mwembechai Mosque in Dar es Salaam on the grounds that he was threatening peace and stability through his provocative sermons. In a demonstration that followed the arrest, two people were shot dead by the police and 135 demonstrators were arrested.
From the constitutional amendment of 1992 sprang the elections of October 1995, the first multiparty elections in Tanzania since the 1960s. However, the CCM commitment to a fair and open election was questioned. CCM candidate Benjamin Mkapa was elected union president in a vote that opposition parties and international observers considered flawed. On Zanzibar, international observers and the opposition Civic United Front (CUF) believed that CCM intimidation and vote rigging influenced the election results for the islands' government to favor CCM. The CUF claimed victory, only to have the CCM reject the results. The CCM-dominated electoral commission then declared CCM candidate Salmin Amour the winner of the presidential race, and gave the CCM the majority of seats in Zanzibar's House of Representatives. CUF boycotted sessions of the Zanzibar House and refused to recognize the Amour government until a 1999 Commonwealth brokered agreement was reached between the two rival parties. Despite the agreement, political tensions on the islands were high as the October 2000 elections approached.
Among the major problems inherited by Mkapa was the fate of the 700,000 refugees living in camps near the northern and western borders. Tanzania had taken in some 500,000 Rwandan refugees who fled the violence in their country since 1980. In one day at the height of the 1994 genocide in Rwanda, 200,000 refugees crossed over the border. Additionally, the government took in 200,000 refugees from Burundi. The strain on the country's resources, coupled with incursions into Tanzania by Tutsi dominated Burundi government forces chasing Hutu rebels, led the government to close its borders in 1995. In February 1997, Tanzania implemented its much-criticized plan to repatriate or expel its refugee population. In 1998 Tanzania severed its relations with Burundi and refused to recognize the military government of Major Pierre Buyoya. In response, Burundi closed its embassy in Dar es Salaam. Repatriation of Rwandan refugees was nearly completed by end of 2002.
On 7 August 1998, simultaneous bombings of the US embassies in Nairobi and Dar es Salaam—claiming twelve Tanzanian lives—were attributed to Osama bin Laden's al-Quaeda organization. Combined investigations and close cooperation between the Tanzanian and US governments facilitated the capture of a number of the terrorists. However, in early 2003 Western governments issued warnings to their citizens of possible terrorist threats on Zanzibar, which had a devastating impact on the economy with some hotel bookings down by 50%.
In October 2000, Tanzanians went to the polls re-electing Benjamin Mpaka and giving the ruling CCM party 244 of 272 seats in the parliament. The CUF disputed the results in Zanzibar, and in January 2001 after the government declared a protest march illegal, security forces shot and killed approximately 30 persons, seriously injured 300, and displaced some 2,000 more. On 26 February 2001, in what appeared to be a revenge murder, the CCM secretary-general for Pemba was found killed with machete slashes to his skull and body. Following year-long talks between the CCM and CUF, a constitutional amendment act was passed by the Zanzibari parliament on Pemba island towards the implementation of a reconciliation agreement signed by the two parties in October 2001. The passage of the Act meant a review of the judiciary and Zanzibar Electoral Commission (ZEC), as well as the introduction of a director of public prosecution.
In June 2003, Tanzania was set to participate in the first of two scheduled summits on peace and development in the Great Lakes region. Findings from a UN assessment team asserted that seven nations—Tanzania, Uganda, Rwanda, Burundi, DRC, Angola, and South Africa—were key to peace in the sub-region.
As of mid-2003, Tanzania faced a number of issues and challenges. According to the UNDP human development report for 2002, Tanzania ranked 151 out of 173 countries making it one of the world's poorest nations. The HIV adult prevalence rate was 11% with over two million people infected with the virus. The US State Department report on democracy and human rights observed that while Tanzania had improved its respect for human rights in recent years, the government's overall record remained poor. The report found that police were more disciplined in 2002, but members of the police and security forces committed unlawful killings and mistreated suspected criminals. The most serious violations of human rights resulted from election-related violence in Zanzibar in 2001.