In very ancient period the country around Basti was part of Kosala. The Shatapatha Brahmana speaks of Kosala as one of the countries of the Vedic Aryans and the grammarian Pa?ini mentions it in one of his Sutras. It was during the rule of Rama, the eldest son of Dasharatha, that the glory of the Kosala royal dynasty reached its culmination. According to the tradition, Rama’s elder son Kush ascended the throne of Kosala while the younger son Lav became the ruler of the northern part of the kingdom with its capital as Shravasti. In the 93rd generation from Ikshvaku and 30th from Rama was Brihadbala, the last famous king of the Ikshvaku density who was killed in Great Mahabharata battle. With the decline of the Guptas in sixth century CE, Basti also began gradually to become desolate. At this time a new dynasty, that of the Maukharis, with its capital as Kannauj, assumed an important position on the political map of northern India and perhaps this kingdom in included present district also. In the beginning of the 9th century CE, the Gurjara–Pratihara king, Nagabhata II, overthrew the Ayodhyas who was then ruling at Kannauj, and made this city the capital of his growing empire which rose to its greatest height in the reign of the famous Mihira Bhoja I (836-885 A.D.). During the reign of Mahipal, the power of Kannauj began to decline and Awadh was divided into small chieftainships, but all of them ultimately yielded to the newly rising power of Gahadwals of Kannauj. Jaychandra (1170-1194 A.D.), the last important ruler of the dynasty was killed in the battle of Chandawar (near Etawah) fighting against the invading army of Muhammad of Ghor. Soon after his death Kannauj was occupied by the Turks. According to the legends, for centuries Basti was a wilderness and that greater part of Awadh was occupied by the Bhars. No definite evidence is available about the Bhars origin and early history. The evidence of an extensive Bhar kingdom in the district can be gleaned only from the ruins of ancient brick buildings popularly ascribed to the Bhars and found in abundance in a number of villages of this district.
In the beginning of the 13th century CE, Nasir-ud-din Mahmud, the elder son of Iltutmish, became the governor of Awadh in 1225 and is said to have completely crushed all resistance on the part of the Bhars. In 1323, Gayasuddin Tuglaq march through Bahraich and Gonda on his way to Bengal but he seems to have avoided the perils of the forest of district Basti and went by river from Ayodhya. Till 1479 CE, Basti and its adjoining districts appeared to be remained under the control of the rulers of Jaunpur Sultanate. After annexing the Jaunpur Sultanate, Bahlol Lodi handed over the governorship of the area covered by the sultanate to his nephew Muhammad Farmuli (Kala Pahar) with the headquarters at Bahraich, which included this district and the adjoining areas. About this time, Mahatma Kabir, the well-known poet and philosopher lived at Maghar in this district. It is said that before the advent of the leading Rajput clans, there were the local Hindus and Hindu Rajas in the districts and they are said to have supplanted the aboriginal tribes like Bhars, Tharus, Domes and Domekatars, whom general tradition declares to have been the early rulers, at least after the fall of ancient kingdoms and this appearance of the Buddhist faith. These Hindus included the Bhumihar Brahmins, Sarvariya Brahmans and Visen. This was the state of the Hindu society in the district before the arrival of the Rajputs from the west. In the middle of the 13th century the Srinetra was the newcomer to have first established in this reign. Their chief, Chandrasen, expel the Domkatar from the eastern Basti. The Kalhans Rajput of Gonda province established themselves in Pargana Basti. South of the Kalhans country Nagar, ruled by a Gautam Raja. There was also an ailed clan in Mahuli known as Mahsuiyas are Rajputs of Mahso. Other Rajput clan of special mention was that of Chauhan. It is said that three chief Mukund fled from Chittaur who ruled on undivided part (now it is in district Siddharthnagar) of district Basti. By the last quarter of the 14th century Amorha a part of district Basti were ruled by Kayasth dynasty. During the reign of Akbar and his successor the district formed a part of the Gorakhpur sarkar of the Awadh Subah. In the earlier days of his reign the district served as the asylum for the rebel Afghan leaders like Ali Quli Khan, Khan Zaman, the governor of Jaunpur. During the Mughal period in 1680 Aurangzeb sent one Qazi Khalil-ur-Rahman as the chakledar (holder of the tract) of Gorakhpur probably to get the regular payment of revenue from the local chiefs. Kalil-ur-Rahman marched from Ayodhya to force the chieftains of the districts adjoining Gorakhpur to make payment of revenue. As a result of this move, the rajas of Amorha and Nagar, who had recently acquired power, promptly tendered their submission and confrontation was thus averted. The governor then proceeded to Maghar which he again garrisoned, compelling the raja of Bansi to retire to this fortress on the bank of Rapti. The town of Khalilabad, now headquarters of newly created district Sant Kabir Nagar, was named after Khalil-ur-Rahman, who tomb was erected at Maghar. A road leading from Ayodhya to Gorakhpur was constructed. In February 1690, Himmat Khan (son of Khan Jahan Bahadur Zafar Jang Kokaltash, Subahdar of Allahabad) was appointed Subahdar of Awadh and faujdar (military commander) of Gorakhpur who held the charge of Basti and adjoining districts for a long time.