In the 1,500 years before Europeans arrived in the area, the lake region of Africa, with its temperate climate and good soil, was a crossroads for invasions of Bantu agriculturists and Nilotic cattle herders. A fusion of these peoples occurred, and by the 15th century, Bunyoro, the first of the great Ugandan kingdoms, had been founded. During the next two centuries its armies brought much of central Uganda under its control. These areas were ruled by governors subordinate to the great king of Bunyoro. In the late 18th century, during a period of conflict, the governor of Buganda declared his independence, and the new kingdom quickly became the major lake state. Two smaller kingdoms, Ankole and Toro, also became independent of Bunyoro. Each of these, with variations, modelled its society and political system on the mother state. Buganda was ruled by a semi-divine king (kabaka) who was advised by a council of great nobles (lukiko), and the land was divided among the nobility and farmed by the peasants. Cattle were symbols of power and were owned by the nobility. The state was defended by a standing and conscript army obedient to the king's desires. Although powerful, Buganda never completely dominated the other kingdoms and scattered Bantu groups.
The first Europeans to visit Uganda were the British explorers John Hanning Speke and James Grant, when they were searching for the source of the River Nile in 1862. They were followed by Samuel White Baker and Charles George Gordon, commanding Egyptian troops. The explorer Henry Morton Stanley, welcomed by Kabaka Mutesa I (reigned 1852-1884), reported the king's eagerness to understand Christianity. Soon both Protestant and Roman Catholic missionaries were working in Buganda. Within a decade the factions they created caused a civil war. Once isolated, the region, had become by 1890 a major object of the European nations' scramble for African territory. Britain, after securing German recognition of its rights, moved to secure Buganda. Frederick Lugard, working for the British East Africa Company, ended the civil disturbances and his successors used the Bugandan army to help conquer the other kingdoms and peoples. By 1896 a British protectorate administration had extended its authority over most of the region and the name Uganda was adopted. Final details concerning the administration of Uganda were settled by a series of agreements in 1900, the most comprehensive of which guaranteed special status to Buganda, including the continuation of its social and political system.
Britain's almost 70 years of rule in Uganda took the form of a centralized European bureaucracy, which was superimposed on a federation of kingdoms and peoples. This worked relatively well until the independence movements of the 1950s when Buganda demanded separation from Uganda. Only after Kabaka Mutesa II was exiled for two years in 1953 was it possible to proceed with developing a united government. After much experimentation, a federal constitution was promulgated in April 1962. The Uganda People's Congress won the elections and Milton Obote became prime minister. Independence was granted in October. Dissension continued, however, and in May 1966 Obote sent the army into Buganda and drove the kabaka into exile. He then proclaimed a new republican constitution, formally abolished the kingships, and became Uganda's first president of a unitary government. Bugandan recalcitrance, a fall-off in the economy, and charges of corruption led to an army coup in January 1971. Power devolved upon the army commander Idi Amin, who began eight years of terror and misrule. He increased the size of the army, murdered his political opponents, and began a reign of terror directed at the people of Buganda, Obote's Lango people, and at their neighbours, the Acholi. It is estimated Amin ordered the killing of around 300,000 Ugandans. He also expelled more than 60,000 Asians, many of whom were entrepreneurs, from the country (1972). By 1978 Uganda was bankrupt, in the grip of internecine warfare, and the government dependent on massive loans from Arab states friendly to Amin.
After Uganda went to war with neighbouring Tanzania in late 1978, Tanzanian forces allied with Ugandan rebels drove Amin from the country. He was allowed to escape to and settle in Saudi Arabia. Three provisional presidents served before elections were held in December 1980. Obote's party won amid widespread reports of electoral fraud, and he became the president once again. Uganda, however, had changed fundamentally. Once thriving, the nation had suffered prolonged economic disaster, with an inflation rate of more than 200 per cent, no consumer goods, few jobs, rampant crime, famine in the north, and no effective government in the countryside. In 1982, after Tanzanian troops had been withdrawn, anti-government guerrillas became active, bloody internecine feuds (a legacy of the Amin period) flourished, and thousands of young men were arrested, suspected of being guerrillas. Thereafter, Obote's regime became as murderous and autocratic as Amin's. More than 100,000 Ugandans were killed or starved to death over the next three years.
In July 1985 a coup overthrew the government; Obote fled the country and settled in Zambia. The National Resistance Army, led by Yoweri Museveni, took over the country in January 1986. Among its first priorities was the re-building of a nation state from a country reduced after 15 years of misrule and violence into feuding factions. By involving all ethnic groups in the government, as well as most of the main political parties, the pragmatic Museveni largely succeeded in this. Peace was restored to almost all the country, except the northern border area near Sudan, where small rebel groups concentrated, and where arms were readily available from the civil war in Sudan.
Uganda's relationship with Rwanda, which had been strained in the late 1980s, improved after the introduction of a cooperation agreement between the two countries in August 1992, which sought to improve border security. With the assistance of large-scale foreign aid, efforts were made to rebuild the economy and infrastructure. Former Asian residents were invited to return, and a programme of economic liberalization introduced to bring the budget under control, encourage agricultural production, and attract foreign investors. During 1993 and 1994 debate began on a new constitution, as the first stage in a process of returning the country to a democratic government.
A new constitution came into force in 1995, which made provision for a referendum in 2000 on the introduction of a multi-party system. It also legalized political parties although still banned them from any activity. In the 1996 presidential election Museveni was returned to power, having won 74 per cent of the popular vote. In the 1990s Museveni grew in prestige as an African statesman.
In April 2001, Uganda announced that it would finally be withdrawing its troops from the Democratic Republic of the Congo (DRC), where they had been deployed in backing the rebels against the government since 1998. Uganda's intervention in the conflict had received international condemnation, and had led to battles with Rwandan forces, also in the country. Troops were pulled out of the DRC in May 2001. Uganda and Rwanda signed a peace agreement in November 2001, brokered by British minister Claire Short. In March 2004 the presidents of Uganda and the neighbouring Kenya and Tanzania signed a protocol for the introduction of a customs union between the three countries. A constitutional amendment was approved in 2005 that paved the way for President Museveni to stand for a third term. He duly won the election held in February 2006 by gaining 59 per cent of the vote.