The same year that Sanjar pardoned Atsïz, the Kara Khitai under Yelü Dashi defeated the Seljuks at Qatwan, near Samarkand.
The portion of the Seljuk army that refused to join the Oghuz proclaimed the former ruler of the Karakhanids, Mahmud Khan, as their leader.
Atsïz and his son Il-Arslan departed from Khwarazm, but before they could make any gains Sanjar escaped from his captivity and restored his rule.
Towards the end of his life, Atsiz subordinated the entire northwestern part of Central Asia, and in fact, achieved its independence from the neighbors.
[6] Atsiz is often addressed in the panegyric qasidas of his poet laureate and chief secretary Rashid al-Din Vatvat (died 1182/3).