The colonial history of Kenya dates from the establishment of a German protectorate over the Sultan of Zanzibar's coastal possessions in 1885, followed by the arrival of the Imperial British East Africa Company in 1888. Incipient imperial rivalry was forestalled when Germany handed its coastal holdings to Britain in 1890. This was followed by the building of the Kenya–Uganda railway passing through the country. This was resisted by some tribes — notably the Nandi led by Orkoiyot Koitalel Arap Samoei for ten years from 1890 to 1900 — still the British eventually built the railway. The Nandi were the first tribe to be put in a native reserve to stop them from disrupting the building of the railway. During the railway construction era, there was a significant inflow of Indian peoples, who provided the bulk of the skilled manpower required for construction.
While building the railroad through Tsavo, a number of the Indian railway workers and local African labourers were attacked by two lions known as the Tsavo maneaters. They and most of their descendants later remained in Kenya and formed the core of several distinct Indian communities such as the Ismaili Muslim and Sikh communities.
At the outbreak of World War I in August 1914, the governors of British East Africa (as the Protectorate was generally known) and German East Africa agreed a truce in an attempt to keep the young colonies out of direct hostilities. Lt Col Paul von Lettow-Vorbeck took command of the German military forces, determined to tie down as many British resources as possible. Completely cut off from Germany, von Lettow conducted an effective guerilla warfare campaign, living off the land, capturing British supplies, and remaining undefeated. He eventually surrendered in Zambia eleven days after the Armistice was signed in 1918. To chase von Lettow the British deployed the British Indian Army troops from India and then needed large numbers of porters to overcome the formidable logistics of transporting supplies far into the interior on foot. The Carrier Corps was formed and ultimately mobilised over 400,000 Africans, contributing to their long-term politicisation.
During the early part of the 20th century, the interior central highlands were settled by British and other European farmers, who became wealthy farming coffee and tea. (One depiction of this period of change from one colonist's perspective is found in the memoir "Out of Africa" by Danish author Baroness Karen von Blixen-Finecke, published in 1937.) By the 1930s, approximately 30,000 white settlers lived in the area and gained a political voice because of their contribution to the market economy. The area was already home to over a million members of the Kikuyu people, most of whom had no land claims in European terms, and lived as itinerant farmers. To protect their interests, the settlers banned the growing of coffee, introduced a hut tax, and the landless were granted less and less land in exchange for their labour. A massive exodus to the cities ensued as their ability to provide a living from the land dwindled. By the 1950s, the white population numbered 80,000.
In 1952, Queen Elizabeth II and her husband Prince Phillip were on holiday at the Treetops Hotel in Kenya when her father, King George VI, passed away in his sleep. The young princess cut-short her trip and returned home immediately to take her throne. Queen Elizabeth II was crowned at the Westminster Abbey in 1953 and, as one gentleman put it, she went up a tree in Africa a princess, and came down a queen.
From October 1952 to December 1959, Kenya was under a state of emergency arising from the Mau Mau rebellion against British rule. The governor requested and obtained British and African troops, including the King's African Rifles. The British began counter-insurgency operations; in May 1953 General Sir George Erskine took charge as commander-in-chief of the colony's armed forces, with the personal backing of Winston Churchill.
The capture of Warũhiũ Itote (aka General China) on 15 January 1954 and the subsequent interrogation led to a better understanding of the Mau Mau command structure. Operation Anvil opened on 24 April 1954, after weeks of planning by the army with the approval of the War Council. The operation effectively placed Nairobi under military siege, and the occupants were screened and the Mau Mau supporters moved to detention camps. The Home Guard formed the core of the government's strategy as it was composed of loyalist Africans, not foreign forces like the British Army and King's African Rifles. By the end of the emergency, the Home Guard had killed 4,686 Mau Mau, amounting to 42% of the total insurgents. The capture of Dedan Kimathi on 21 October 1956 in Nyeri signified the ultimate defeat of the Mau Mau and essentially ended the military offensive. During this period, substantial governmental changes to land tenure occurred. The most important of these was the Swynnerton Plan, which was used to both reward loyalists and punish Mau Mau.