As per the history of Gorakhpur District, it was a part of the famous kingdom of Koshal, one of the sixteen mahajanapadas in 6th Century BC. The earliest known monarch ruling over this region with his capital at Ayodhya was Ikshvaku, who founded the Solar Dynasty of Kshatriyas. Ikshvaku Dynasty produced a number of illustrations kings till the accession of Lord Rama, who was the greatest ruler of this dynasty. Since then, it remained an integral part of the erstwhile empires like Maurya Empire, Shunga Dynasty, Kushana Empire, Gupta and Harsha dynasties. According to some legends, Tharu king, Madan Singh (900 AD - 950 AD) ruled over Gorakhpur city and the adjoining areas.
In medieval period, when the entire northern India lay prostrate before the Muslim ruler, Muhammad Ghori, Gorakhpur region was not left out. For a longer period it remained under the sway of the Muslim rulers, from Qutub-Ud-Din Aibak to Bahadur Shah. Tradition has it that Ala-ud-din Khilji (1296-1316) ordered the conversion of old shrine of Goraksha (a popular deity) of Gorakhpur into a mosque. However, on Akbar's re-organisation of the empire, Gorakhpur gave its name to one of the five Sirkars comprising the province of Awadh.
Modern period of the history of Gorakhpur District was marked by the transfer of this region by Nawab of Avadh to the East India Company in 1801. With this cession, Gorakhpur was raised to the status of a district. In 1829, Gorakhpur was made the headquarters of Gorakhpur Division, comprising the districts of Gorakhpur, Ghazipur and Azamgarh. In 1865, new district Basti was carved out from Gorakhpur. The latter was further split up in 1946 to form new district Deoria. The third division of Gorakhpur led to the creation of district Mahrajganj in the year 1989.