Tanzania's history as a unified state began on April 26, 1964, when Tanganyika and Zanzibar merged to form the United Republic of Tanzania, three months after the Zanzibar Revolution of January 12, 1964. The mainland territory of Tanganyika had gained independence from Britain on December 9, 1961, under the leadership of Julius Nyerere and the Tanganyika African National Union. Zanzibar achieved independence on December 10, 1963, ending over 70 years of British protectorate status that had formalized the Sultanate of Zanzibar's position. The January 1964 revolution overthrew Sultan Jamshid bin Abdullah and ended Arab political dominance within 12 hours of fighting, leading to Abeid Karume's establishment of the People's Republic of Zanzibar and Pemba. The union between Tanganyika and Zanzibar created Africa's largest country by combining 362,000 square miles of mainland territory with the 1,020 square miles of the archipelago, though Zanzibar retained separate governance structures for internal affairs that persist today.
The Arusha Declaration of February 5, 1967, transformed Tanzania's economic and social structure through Julius Nyerere's policy of Ujamaa, a Swahili term meaning familyhood or collective farming. Nyerere announced nationalization of major industries including banks, insurance companies, and trading firms, while declaring education, land, and all major means of production as public property. The declaration mandated that political leaders could not hold shares in companies, own rental properties, or receive multiple salaries, establishing Tanzania as one of Africa's most explicitly socialist states. Between 1967 and 1977, the government relocated approximately 11 million rural residents into planned villages called Ujamaa villages, moving roughly 70 percent of Tanzania's population in what became one of the largest forced resettlement programs in African history. Agricultural production declined during this period, with Tanzania shifting from a net food exporter in the 1960s to requiring food imports by the mid-1970s. The villagization program formally ended in 1977, though its economic effects persisted through the 1980s when Tanzania recorded some of the continent's lowest per capita GDP figures.
Tanzania and Uganda fought a war from October 1978 to June 1979 after Ugandan President Idi Amin ordered the invasion of northwestern Tanzania on October 30, 1978, claiming sovereignty over the Kagera Salient, a 710 square mile triangular region south of the Kagera River. Ugandan forces occupied approximately 700 square miles of Tanzanian territory and withdrew only after looting the region. Julius Nyerere mobilized the Tanzania People's Defence Force and launched a counteroffensive in January 1979, crossing into Uganda with 45,000 troops alongside the Uganda National Liberation Front, a coalition of Ugandan exile groups. Tanzanian forces captured Kampala on April 11, 1979, ending Amin's eight-year rule, then advanced to secure the Nile bridges and northern Uganda despite initial resistance. The war cost Tanzania an estimated 500 million US dollars, representing more than half the country's annual GDP at the time, and resulted in approximately 1,000 Tanzanian military casualties. Tanzania maintained 10,000 troops in Uganda until June 1981 to support the transitional government, withdrawing only after Milton Obote's contested election in December 1980. The conflict severely damaged Tanzania's already strained economy, contributing to the economic crisis that forced adoption of International Monetary Fund structural adjustment programs in 1986.
The liberalization period beginning in 1986 dismantled most of Nyerere's socialist economic framework after Tanzania signed its first agreement with the International Monetary Fund in August 1986. President Ali Hassan Mwinyi, who succeeded Nyerere in November 1985, implemented currency devaluation that saw the Tanzanian shilling fall from 17 per US dollar in 1986 to 300 per US dollar by 1992. The government began privatizing state-owned enterprises in 1992 through the Parastatal Sector Reform Commission, eventually selling or liquidating over 350 state companies between 1992 and 2005. The 1995 constitution introduced multiparty democracy, ending the single-party system that had existed since 1965 when Tanganyika African National Union merged with Zanzibar's Afro-Shirazi Party to form Chama Cha Mapinduzi. Tanzania's first multiparty elections occurred on October 29, 1995, with Benjamin Mkapa winning the presidency with 62 percent of votes, though Zanzibar's elections were disputed with the opposition Civic United Front claiming fraud in results showing 50.2 percent for the ruling party. GDP growth averaged 4.2 percent annually through the 1990s compared to 2.1 percent in the 1980s, while inflation declined from peaks above 30 percent to single digits by 1999.
The Zanzibar political crisis erupted on January 27, 2001, when security forces killed at least 35 opposition supporters protesting alleged fraud in the October 2000 elections that returned Amani Karume as Zanzibar president with 67 percent of votes. The Civic United Front had rejected results showing they received 33 percent of votes, claiming systematic ballot manipulation in constituencies where their observers were excluded. Commonwealth observers documented irregularities including multiple voting, but the Zanzibar Electoral Commission refused demands for a recount. Security forces opened fire on protesters in Zanzibar City's Migombani area, with Human Rights Watch documenting 35 confirmed deaths and over 600 arrests in subsequent weeks. An estimated 2,000 Zanzibaris fled to Kenya as refugees between January and March 2001. The Commonwealth suspended observer missions to Zanzibar, and several European donors reduced aid to Tanzania's union government. Negotiations mediated by former South African president Thabo Mbeki produced the Muafaka agreement in October 2001, establishing a Government of National Unity that allocated cabinet positions to opposition parties, though implementation faced repeated delays until 2010 when a formal power-sharing arrangement finally allocated the first vice president position to the opposition.
The 1998 United States embassy bombing in Dar es Salaam killed 11 people on August 7, 1998, when a truck bomb exploded outside the embassy compound at 10:39 AM local time, eight minutes after a larger explosion at the Nairobi embassy killed 213 people. The Dar es Salaam bomb killed 11 Tanzanians but no Americans, as the embassy building's distance from the street and structural reinforcements reduced casualties. The attack destroyed the Filabusi Building adjacent to the embassy and damaged structures within a 200-meter radius. Al-Qaeda operatives had surveilled the embassy for months, with cell members photographing the compound from nearby buildings. The United States indicted 17 defendants including Osama bin Laden in November 1998, with trials beginning in January 2001 in New York resulting in convictions for four participants by May 2001. Tanzania received 42 million US dollars from the United States to construct a new embassy compound, completed in 2003 in the Msasani Peninsula area at a distance from surrounding buildings. The bombing prompted Tanzania to increase intelligence cooperation with Western agencies, though the country maintained its policy of minimal military involvement in international conflicts.