Kenya's recorded history begins with Indonesian and Arab traders, who by the early Middle Ages were visiting the coast to trade. The Kenyans of that era were of the mixed Semito-Hamitic and Negro stock now known as Nilotic. A great influx of Bantu peoples from the northwest began in the 13th century. The Bantus occupied the most desirable areas, Swahili groups settling on the coast.

Mombasa and Malindi were wealthy centers of Indian Ocean trade when Portuguese explorers reached the east coast of Africa at the end of the 15th century. The Portuguese plundered and destroyed the coastal cities and took control of the trade for the next century. As Portugal's sea power declined, Arabs helped the Swahilis expel the Portuguese and reestablished themselves as masters of the coast.

In the late 19th century both Germany and Great Britain were building colonial empires in Africa. An agreement with Germany in 1886 permitted Britain to take control in the interior of Kenya; an 1887 agreement with the Arab sultan of Zanzibar gave Britain control of the coastal strip. In 1895 the country was made a British protectorate under the name British East Africa. A railroad from Mombasa to Lake Victoria was completed in 1901, and white colonization of the interior began. In 1920 some territory in the northeast was ceded to Italy. The remaining interior area became the Colony of Kenya; the coastal strip became Kenya Protectorate.

After World War II African nationalism developed rapidly under Kikuyu leadership. A secret terrorist organization, the Mau Mau, was formed to drive the whites from Kenya. From 1952 to 1956 there were many bloody but unsuccessful attempts to expel the British. By 1957 the Mau Mau uprising had been put down. Jomo Kenyatta, accused of being its leader, was imprisoned.

A movement for self-rule was led by Tom Mboya, a Luo, in cooperation with the Kikuyus. A constitution was drawn up in 1962 and self-government was inaugurated. In 1963 the coastal strip was ceded to Kenya by Zanzibar. In the same year Kenya gained independence, as a dominion in the British Commonwealth, and Kenyatta became prime minister. The country became a republic in 1964 with Kenyatta as president.

Kenyatta and Mboya, his minister of economics, were able to maintain peace among the Kikuyu, Luo, and other groups, but the country's stability was threatened from another source—a Somalian-supported secessionist movement in the north. It was quelled after four years of guerrilla warfare. Stability was again threatened in 1969, when Mboya was assassinated and a Kikuyu was accused of his murder. For a time there was serious violence, but eventually the unrest subsided.

Under Kenyatta's rule, Kenya became the most prosperous nation in East Africa. Kenyatta died in 1978 and was succeeded by Daniel Arap Moi. Falling prices for the country's two principal exports, coffee and tea, caused a depression during the first years of Moi's rule, but the economy revived in the mid-1980's when world prices for these commodities rose. Moi was reelected president in 1992 in the first multiparty election in 26 years. Moi stepped down as president in 2002 and was succeeded by Mwai Kibaki.