In 1001 Mahmud of Ghazni first invaded modern day Afghanistan and Pakistan and then parts of India. Mahmud defeated, captured, and later released the Shahi ruler Jayapala, who had moved his capital to Peshawar (modern Pakistan). Jayapala killed himself and was succeeded by his son Anandapala.