In 840, the Kyrgyz allied with the Tang dynasty to defeat the Uyghur Khaganate (Mongolia). The Kyrgyz qaghan (king) killed the Uyghur qaghan and rescued Princess Taihe. They moved to Jeti-su and spread south to the Tian Shan mountains and Xinjiang. The Kyrgyz then lived peacefully around Central Asia and Xinjiang, as vassals to the Tang.