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. Imperial rivalry was prevented when Germany handed its coastal holdings to Britain in 1890. This was followed by the building of the Uganda Railway passing through the country.
The building of the railway was resisted by some ethnic groups—notably the Nandi, led by Orkoiyot Koitalel Arap Samoei for ten years from 1890 to 1900—however the British eventually built the railway. The Nandi were the first ethnic group 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 influx of Indian workers, who provided the bulk of the skilled manpower required for construction. 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.
While building the railway through Tsavo, a number of the Indian railway workers and local African labourers were attacked by two lions known as the Tsavo maneaters.
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 initially agreed on a truce in an attempt to keep the young colonies out of direct hostilities. However Lt. Col. Paul von Lettow-Vorbeck, the German military commander, determined to tie down as many British resources as possible. Completely cut off from Germany, Lettow-Vorbeck conducted an effective guerrilla warfare campaign, living off the land, capturing British supplies, and remaining undefeated. He eventually surrendered in Northern Rhodesia (today Zambia) fourteen days after the Armistice was signed in 1918.