According to tradition, the founder of the Batswana tribe was a 14th-century chief named Mogale. His great-great-grandson Malope had three sons, Kwena, Ngwaketse, and Ngwato, who became the chiefs of the major tribes that now inhabit Botswana.
The foundations of the modern state lie in the 1820–70 period, when the Batswana suffered many tribulations at the hands of the Matabele. In 1872, Khama III became chief of the Bamangwato. He was the son of Chief Sekgoma, the only Batswana chief who had succeeded in turning back the Matabele. Up to that time, the Batswana had no permanent contact with Europeans, except for the missionaries Robert and Mary Moffat and David Livingstone, who had established missions in the first half of the 19th century. But with increased exploration and the partition of southern Africa among the European powers, hostility developed between the Batswana and the Boer trekkers from the Transvaal. Khama III appealed to the UK for assistance, and in 1885 the whole of what was then known as Bechuanaland was proclaimed to be under the protection of Queen Victoria. The territory south of the Molopo River was constituted a crown colony called British Bechuanaland, and in 1895 it was incorporated into South Africa. The northern part of the territory, the Bechuanaland Protectorate, remained under the protection of the British crown, the powers of which, beginning in 1891, were exercised by the high commissioner in South Africa. The South African Act of Union of 1909, which created the Union (now Republic) of South Africa, provided for the eventual transfer to South Africa of Bechuanaland and the two other High Commission Territories, Basutoland and Swaziland, despite their requests to the contrary. The provision was dropped in 1961, after the withdrawal of South Africa from the Commonwealth.
The first significant political progress was made in 1921–22 with the creation of European and African advisory councils, added to which was a joint advisory council. In 1961, executive and legislative councils were created. A major step on the road to independence was taken in 1965 with the implementation of Bechuanaland's self-government constitution under Seretse Khama, the former chief-designate of the Bamangwato, who had become prime minister after Bechuanaland's first general elections. Final constitutional talks were held in London in February 1966, and on 30 September 1966, under the leadership of President Khama, the newly named Republic of Botswana came into being.
On 18 October 1969, the Botswana Democratic Party (BDP), under the leadership of Sir Seretse Khama, was returned to power in the general elections, and he was sworn in for a second term as president on 22 October. Khama was reelected president after the BDP won 27 out of 32 regular elective seats in the National Assembly in national elections held on 26 October 1974. During this first decade of independence, Botswana refused to support UN sanctions against South Africa because, although officially opposed to apartheid, Botswana recognized its own economic dependence on South Africa. Following the 1969 elections, President Khama banned the import of goods from the white minority regime in Rhodesia (now Zimbabwe). Tensions were high in the 1970s as Botswana harbored 20,000 refugees from Rhodesia, and Rhodesian forces several times crossed into Botswana on "hot pursuit" raids against guerrillas.
In elections held in October 1979, the BDP won 29 of the 32 elective seats, and Khama was elected to a fourth presidential term. He died in 1980 and was succeeded by Vice President Quett Ketumile Joni Masire, who was elected to a full five-year term on 10 September 1984. Masire was reelected on 7 October 1989 and the BDP won 31 and the BNF 3 of the elected assembly seats.
South Africa repeatedly, but fruitlessly, pressed Botswana to sign a mutual-security agreement, and it accused Botswana of harboring insurgents opposed to the Pretoria regime and allowing them to mount acts of terrorism and sabotage against South Africa, a charge Botswana denied. An attack by South African commandos on 14 June 1985, aimed at South African refugees, killed at least 15 people in Gaborone. Further South African border violations and attacks on targets in Botswana took place during 1986, but such incursions had ended by 1988 and in 1992 the two countries established formal diplomatic relations.
Before the 1994 legislative elections, the assembly was expanded to 44 seats, 40 of which would be elected, with the majority party given the right to appoint the remaining 4 seats. The opposition maneuvered before the election, attempting to form a broad coalition to unseat the BDP, which had so dominated the country since independence. Many opposition politicians insisted on electoral reforms, specifically the introduction of absentee balloting (20% of the population is migrant workers) and the lowering of the voting age from 21 to 18. On 15 October the elections were held and, as expected, the BDP won a significant majority of seats in the assembly. The assembly named Masire president on 17 October. In November 1995, amidst worsening economic conditions and civil unrest, the government announced constitutional reforms, which limited the president to two terms, although a stipulation was added that the rule would not apply to the sitting president. The voting age was also lowered to 18, but no action was taken to introduce absentee balloting.
On 1 April 1998, Festus Mogae succeeded Quett Masire after the latter stepped down. Mogae was subsequently elected president in the 16 October 1999 polls with 54.3% of the National Assembly vote. He has faced a number of issues such as environmental degradation, the need to diversify the economy, and political power struggles within the ruling party. With the backing of Mogae, Vice-President Lt-Gen. Seretse Ian Khama was expected to challenge BDP national chairman, Ponatshego Kedikilwe, for the chairmanship of the party at the BDP's biannual congress in July 2003. Pundits ventured that if Kedikilwe won there would be a strong possibility that he would challenge and beat Mogae for the presidency in 2004. However, a Mogae victory in July would virtually assure him of serving a second and final term in office.
Political and economic challenges have taken a back seat to the HIV/AIDS pandemic. Approximately 38.5% of 15–49 year olds is infected—the highest adult prevalence rate in the world. The government's goal was to have no new infections by 2016, and Botswana has been commended for being the first country in Africa to widely distribute antiretroviral drugs through its public health system.