According to The History of the Yorubas by Samuel Johnson, Eso Ikoyi chiefs in the retinue of the first Alake of the Egbas joined him in founding a new community - the confederacy of towns that became known as Orile Egba - in the forest after they left the nascent Oyo empire in around the 13th century AD.
The city was founded because of its strong defensive physical position by refugees trying to protect themselves against slave raiders from Dahomey, who were trying to benefit from the war.
The Gbagura section of Nigeria originally included 144 townships scattered all over Yorubaland stretching all the way to modern day Ibadan.
Sporadic fighting continued with the people of Ota (1842), Ado (1844), Ibarapa (1849), Dahomey (1851), Ijebu-Ere (1851), Ijaye (1860–1862) and the Makun War of 1862–1864.
In 1904, an agreement was made where the British assumed jurisdiction in certain legal cases, and in the same year, the Alake Gbadebo paid a state visit to England.
Over the following years, the British steadily assumed more responsibility for administration while continuing to formally recognize the Egba state.