The history of Uganda comprises the history of the people who inhabited the territory of present-day Uganda before the establishment of the Republic of Uganda, and the history of that country once it was established. Evidence from the Paleolithic era shows humans have inhabited Uganda for at least 50,000 years. The forests of Uganda were gradually cleared for agriculture by people who probably spoke Central Sudanic languages. 
 In 1894, Uganda became a protectorate of the British Empire, and in 1962 the United Kingdom granted independence to Uganda making Sir Edward Muteesa II of Edward Muteesa Walugembe the first President of Uganda and Kabaka of Buganda. Idi Amin deposed Milton Obote to became ruler of Uganda in 1971, a position he would occupy for eight years until he was ousted in 1979 as a result of the Uganda-Tanzania War. After a series of other leaders since Amin's fall, Yoweri Museveni came to power in 1986 and has led Uganda since that time.
 Paleolithic evidence of human activity in Uganda goes back to at least 50,000 years, and perhaps as far as 100,000 years, as shown by the Acheulean stone tools recovered from the former environs of Lake Victoria, which were exposed along the Kagera River valley, chiefly around Nsonezi.
 The cultivators who gradually cleared the forest were probably Bantu-speaking people, whose slow but inexorable expansion gradually took over most of sub-Saharan Africa. They also raised goats and chickens, and they probably kept some cattle by 400 BCE. Their knowledge of agriculture and use of iron-forging technology permitted them to clear the land and feed ever larger numbers of settlers. They displaced small bands of indigenous hunter-gatherers, who relocated to the less accessible mountains.
 Meanwhile, by the first century CE and possibly as early as the fourth century BCE in Western Tanzania, certain related Bantu-speaking metallurgists were perfecting iron smelting to produce medium grade carbon steel in pre-heated forced-draught furnaces. Although most of these developments were taking place southwest of modern Ugandan boundaries, iron was mined and smelted in many parts of the country not long afterward.
 In the 1890s, 32,000 labourers from British India were recruited to East Africa under indentured labour contracts to construct the Uganda Railway. Most of the surviving Indians returned home, but 6,724 decided to remain in East Africa after the line's completion. Subsequently, some became traders and took control of cotton ginning and sartorial retail.
 From 1900 to 1920, a sleeping sickness epidemic in the southern part of Uganda, along the north shores of Lake Victoria, killed more than 250,000 people.
 Britain granted independence to Uganda in 1962, although elections leading to internal self-governance were held on 1 March 1961. Benedicto Kiwanuka of the Democratic Party became the first chief minister. Milton Obote was elected Prime Minister in April 1962 and Uganda became a republic in October 1962, maintaining its Commonwealth membership.
 In succeeding years, supporters of a centralized state vied with those in favor of a loose federation and a strong role for tribally-based local kingdoms. Political maneuvering climaxed in February 1966, when Milton Obote, the Prime Minister, suspended the constitution and assumed all government powers, removing the positions of president and vice president. In September 1967, a new constitution proclaimed Uganda a republic, gave the president even greater powers, and abolished the traditional kingdoms.
 After a military coup on 25 January 1971, Obote was deposed from power and the dictator Idi Amin seized control of the country. Amin ruled Uganda with the military for the next eight years and carried out mass killings within the country to maintain his rule. 
 In 1972, under the so-called "Africanization" policy under Idi Amin, about 40,000 ethnic Indians with British passports were forced to leave Uganda. Approximately 7,000 were invited to settle in Canada; however, only a limited number accepted the offer, and the 2006 census reported 3,300 people of Ugandan origin in Canada. The loss of the entrepreneurial Indian minority left the country's economy in ruins. 
 Amin's eight-year rule produced economic decline, social disintegration, and massive human rights violations. The Acholi and Langi ethnic groups in northern Uganda were particular objects of Amin's political persecution because they had supported Obote and made up a large part of the army. In 1978, the International Commission of Jurists estimated that more than 100,000 Ugandans had been murdered during Amin's reign of terror. Some authorities placed the figure as high as 300,000 — a statistic cited at the end of the 2006 movie The Last King of Scotland, which chronicled part of Amin's dictatorship. Amin's atrocities were graphically recounted in the 1977 book, A State of Blood, written by one of his former ministers after he fled the country, Henry Kyemba.
 Amin's rule ended after the Uganda-Tanzania War in which Tanzanian forces aided by Ugandan exiles invaded Uganda. The conflict started with a border altercation involving Ugandan exiles who had a camp close to the Ugandan border near Mutukula. This resulted in an attack by the Ugandan Army into Tanzania. In October 1978, the Tanzanian Armed Forces repulsed this incursion and, backed by Ugandan exiles, invaded Uganda. Amin's troops were assisted by Libyan soldiers. On 11 April 1979, the capital Kampala was captured and Amin fled with his remaining forces to Libya.
 After Amin's removal, the Uganda National Liberation Front formed an interim government with Yusuf Lule as president and Jeremiah Lucas Opira as the Secretary-General of the UNLF. This government adopted a ministerial system of administration and created a quasi-parliamentary organ known as the National Consultative Commission (NCC). The NCC and the Lule cabinet reflected widely differing political views. In June 1979, following a dispute over the extent of presidential powers, the NCC replaced Lule with Godfrey Binaisa.
 In a continuing dispute over the powers of the interim presidency, Binaisa was removed in May 1980. Thereafter, Uganda was ruled by a military commission chaired by Paulo Muwanga. The December 1980 elections returned the UPC to power under Milton Obote's leadership, with Muwanga serving as vice president. Under Obote, the security forces had one of the world's worst human rights records. In their efforts to stamp out an insurgency led by Yoweri Museveni, they laid waste to a substantial section of the country, especially in the Luwero area north of Kampala.
 The insurgency, the so-called "bush war", was conducted by the National Resistance Army (NRA), under the leadership of Yoweri Museveni, and other rebel groups including the Federal Democratic Movement led by Andrew Kayiira and another led by John Nkwaanga. During the conflict the army carried out mass killings of non-combatants.
 Obote was overthrown on 27 July 1985, when an army brigade, composed mostly of ethnic Acholi troops and commanded by Lt. Gen. Bazilio Olara-Okello, took Kampala and proclaimed a military government. Obote fled to exile in Zambia. The new regime, headed by former defense force commander Gen. Tito Okello (no relation to Lt. Gen. Olara-Okello), opened negotiations with Museveni's insurgent forces and pledged to improve respect for human rights, end tribal rivalry, and conduct free and fair elections. In the meantime, massive human rights violations continued as the Okello government carried out a brutal counter-insurgency in an attempt to destroy the NRA's support.
 Negotiations between the Okello government and the NRA were conducted in Nairobi in the fall of 1985, with Kenyan President Daniel arap Moi seeking a ceasefire and a coalition government in Uganda. Although agreeing in late 1985 to a ceasefire, the NRA continued fighting and seized Kampala and the country in late January 1986, forcing Okello's forces to flee north into Sudan. Museveni's forces organized a government with Museveni as president.
 After assuming power, the government dominated by the political grouping created by Museveni and his followers, the National Resistance Movement (NRM or the "Movement"), largely put an end to the human rights abuses of earlier governments, initiated substantial political liberalization and general press freedom, and instituted broad economic reforms after consultation with the International Monetary Fund, World Bank, and donor governments.
 However, from 1986 to 1994, a variety of rebel groups waged a civil war against the Ugandan government of President Museveni. Most of the fighting took place in the country's north and east, although the western and central regions were also affected. The most important insurgent factions were the Uganda People's Democratic Army (UPDA), the Uganda People's Army (UPA), Alice Auma's Holy Spirit Movement (HSM), and Joseph Kony's army (which later became the Lord's Resistance Army). For further details see War in Uganda (1986-1994).
 In 1996, Uganda was a key supporter of the overthrow of Zairean President Mobutu Sese Seko in the First Congo War in favor of rebel leader Laurent-Désiré Kabila.
 Between 1998 and 2003, the Ugandan Army was involved in the Second Congo War in the Democratic Republic of the Congo.[citation needed] Uganda continues to support rebel groups there such as the Movement for the Liberation of Congo and some factions of the Rally for Congolese Democracy.[citation needed]
 August 2005, Parliament voted to change the constitution to lift presidential term limits, allowing Museveni to run for a third term if he wished to do so. In a referendum in July 2005, 92.5 percent of voters supported the restoration of multiparty politics, thereby scrapping the no-party or "movement" system. Kizza Besigye, Museveni's political rival, returned from exile in October 2005 and was a presidential candidate during the 2006 elections. In the same month, Obote died in South Africa. Museveni won the February 2006 presidential election.
 In 2009, the Anti-Homosexuality Bill was proposed and under consideration. It was proposed on 13 October 2009 by Member of Parliament David Bahati and, had it been enacted, would have broadened the criminalization of homosexuality in Uganda; introduced the death penalty for people who have previous convictions, are HIV-positive, or engage in sexual acts with those under 18; introduced extradition for those engaging in same-sex sexual relations outside Uganda; and, penalized individuals, companies, media organizations, or non-governmental organizations who supported LGBT rights.[citation needed]
 On 11 July 2010, al-Shabaab bombers killed 74 people in Kampala. On 13 September 2014, the Ugandan security and intelligence services, with the assistance of the United States, identified and foiled a major terrorist attack in Kampala. They recovered suicide vests, improvised explosive devices, and small arms, and they arrested 19 people who were suspected to have had links to al-Shabaab. This attack could have been as substantial as the attack in Nairobi during the previous year at Westgate Mall. Instead, it was a failure for al-Shabaab.
 The 2016 Ugandan general election was held in Uganda on 18 February 2016 to elect the president and parliament. Polling day was declared a national holiday. Ahead of the election, Museveni described the formation of an East African Federation uniting Uganda, Tanzania, Kenya, Rwanda, Burundi, and South Sudan as "the number one target that we should aim at." In September 2018 a committee was formed to begin the process of drafting a regional constitution, and a draft constitution for a confederation is set to be written by 2021, with implementation of the confederacy by 2023.
 The 2021 Ugandan general election re-elected president Museveni to a sixth term, but international observers complained of government violence and disinformation, suppression of independent media and opposition campaigning, the arrest of opposition leaders, the shutdown of the Internet, and harassment of observers.  According to official results, Museveni won the elections with 58% of the vote while popstar-turned-politician Bobi Wine had 35%. The opposition challenged the result because of allegations of widespread fraud and irregularities.