After the battle of Panipat (21 April 1526), the rule of Lodi dynasty came to an end Babar became the ruler of Delhi. He sent Humayun to the east. He came to Jaunpur and punished Nasir Khan and obliged him to flee from Ghazipur, which came into Humayun possession, but he short stayed here as he was recalled by the Babar to fight against Rajputs and Afghans. District was soon recaptured by the Afghans, so Babar left Agra on 20 January 1529 and reached Ghazipur. Soon after his return Babar died and his successor Humayun had come to the east where Afghan was rising in which Sher Shah was also included. Humayun had defeated all Afghans including Sher Khan ( Sher Shah) and by a agreement the Chunar Fort gave to him by Humayun. In 1539, the district once again fell to the Afghan under Sher Khan who defeated Humayun at Chausa and assumed the title of Sher Shah at Varanasi. Kam Dev's brother name as Dham Dev who lived at Maa khamakhya Dham near Gahmar also helped Sher Shah Suri in the battle of Chausa. Ghazipur had gone to the house of Sur.