During the 12th century, Muhammad of Ghori's advancing forces captured Ghazni, Multan, Sindh, Lahore, and Delhi, and one of his generals Qutb-ud-din Aybak proclaimed himself Sultan of Delhi and established the first dynasty of the Delhi Sultanate.
Foreign invaders often used abandoned viharas as military cantonments.