Khalili lived and attended school in Kabul until he was 11, when Shāh Habibullāh Khān, king of Afghanistan, was assassinated, purportedly at the behest of his reformist son Amānullāh Khān, who quickly arrested and executed Khalili's father among others associated with the previous regime. Orphaned and unwanted in Kabul, he spent the turbulent years of Amānullāh's reign in the "Shamālī Plain" north of Kabul where he studied classical literature and other traditional sciences with leading scholars and began writing poetry. In 1929, when Habībullāh Kalakānī – a local Tajik from Kalakan – deposed Amānullāh Khān, Khalili joined his uncle Abdul Rahim Khan Safi, the new governor of Herat, where he remained for more than 10 years.