The Republic of Kenya was originally inhabited by hunter-gatherers related to the Khoisan-speaking people of the modern era. These people were probably pushed out of the region by migrating people from the Horn of Africa speaking Cushitic languages. Around 500 BCE Nilotic-speaking pastoralists migrated from what is today the southern part of Sudan, followed in the 1st century CE by Bantu-speaking tribes who introduced metal working and advanced agriculture. During the first few centuries CE, both Arab and Persian traders also made contact and set up coastal trading settlements, which encouraged a more maritime-based economy focusing on trade and shipbuilding. Mombassa became a major port city during the Middle Ages, with slaves and ivory being major exports.
In the mid-19th century, Germany established a protectorate over the coastal regions of present-day Kenya, but these were later ceded to Britain following the arrival of the British East Africa Company. Between 1895 and 1905, the British worked to establish the Kenya-Ugandan railway, fending off local resistance from several indigenous tribes. Subsequent emigration by British and other Europeans saw widespread establishment of prosperous farms and plantations, notably for growing coffee and tea.
Under British law, many native Africans (in particular the Kikuyu) gradually became landless and were forced into labor merely to subsist. By the 1950s, widespread dissatisfaction with the unfairness of the laws and a general resistance to colonialism brought about a popular uprising known as the Mau-Mau Rebellion (1952-1956). The counter-insurgency war, which employed both British and African troops against the tribal guerillas, cost more than 10,000 African lives. Despite defeating the Mau-Mau, Britain eventually conceded to popular elections resulting in a new government under the Kenya African National Union (KANU) of Jomo Kenyatta. In December 1963 Kenya achieved independence, and declared the new Republic of Kenya one year later, with Kenyatta as president. He was succeeded by Daniel arap Moi in 1978 after his death, who remained in office for 24 years. Mwai Kǐbakǐ was elected president in 2002, and remains in office today.