Emperor Taizong's campaign against Xueyantuo

Emperor Taizong of Tang (r. 626-649), the second emperor of Chinese dynasty Tang Dynasty, early in his reign, had allied with Xueyantuo, a vassal of the powerful Eastern Tujue (Göktürk) Khanate, against Eastern Tujue, who Tang defeated in 630. Upon Eastern Tujue's defeat, Xueyantuo's Zhenzhu Khan Yi'nan took over Eastern Tujue's former territory, and while he was formally submissive to Tang, he was expanding his own strength. When Emperor Taizong tried to restore Eastern Tujue in 639 under the Qilibi Khan Ashina Simo (also known as Li Simo) to counteract the rise of Xueyantuo power, Xueyantuo engaged in multiple battles with the newly restored Eastern Tujue, in order to prevent this return. The major Tang general Li Shiji temporarily came to protect Eastern Tujue against Xueyantuo and defeated the Xueyantuo forces in 641. But in 644, with Emperor Taizong occupied with a campaign against Goguryeo, Xueyantuo forces launched a new campaign, defeated Eastern Tujue, forcing Ashina Simo to flee back to Tang. Subsequently, Goguryeo sought aid from Xueyantuo, but Yi'nan avoided further conflict, wanting to avoid direct battle with Tang. After Yi'nan's death in 645, however, his son, the Duomi Khan Bazhuo began heavily battling Tang forces. In 646, Tang forces counterattacked, and after they defeated Bazhuo, Xueyantuo's vassal Huige rose and killed him. His cousin, the Yitewushi Khan Duomozhi, surrendered to Tang forces, ending Xueyantuo.

Cooperation between Tang and Xueyantuo under Yi'nan
Xueyantuo had been long been a member tribe of the Chile confederation, which had in turn been submissive to Tujue, both before and after Tujue's division into Western Tujue and Eastern Tujue, and in the 600s, the Chile had rebelled against Western Tujue's Heshana Khan Ashina Daman, declaring independence under the leadership of Qibi (契苾) chieftain Geleng (歌楞) (with the title Yiwuzhenmohe Khan (易勿真莫賀可汗)) and the Xueyantuo chieftain Yishibo (with the title Yiedie Khan), but later resubmitted to Western Tujue's Shekui Khan.

At some point, the Chile became submissive to Eastern Tujue instead, and as of the reign of the Jiali Khan Ashina Duobi, the Xueyantuo were ruled by Yishibo's grandson Yi'nan. However, Ashina Duobi was said to be a poor ruler, and by 627, several members of the Chile—Xueyantuo, Huige, and Bayegu (拔野谷) had rebelled. Ashina Duobi tried to send his nephew Ashina Yugu against Huige, but Ashina Yagu was defeated by the Huige chieftain Pusa (菩薩), while Xueyantuo defeated four other Eastern Tujue generals, and Ashina Duobi was not able to resubjugate the Chile rebels. Still, in 628, when these Chile tribes offered the title of khan to Yi'nan, Yi'nan did not initially dare to accept it. However, Emperor Taizong of Tang, hearing this and wanting to establish an alliance with Xueyantuo against Eastern Tujue, sent his general Qiao Shiwang (喬師望) to Xueyantuo to create Yi'nan the Zhenzhupieqie Khan (or Zhenzhu Khan in short), and subsequently, a large number of Chile and Tujue tribes came under Yi'nan's rule. Subsequently, Tang and Xueyantuo often exchanged emissaries, and Xueyantuo grew stronger at Eastern Tujue's expense.

In 629, Emperor Taizong commissioned the general Li Jing to lead a major expedition against Eastern Tujue, and in 630, Li Jing captured Ashina Duobi and effectively destroyed Eastern Tujue. Much of the Eastern Tujue people surrendered to Xueyantuo, and some surrendered to Tang. After this event, Xueyantuo was the predominant power north of China, but remained formally submissive to Tang. In 638, Emperor Taizong, with Yi'nan's concurrence, further created Yi'nan's sons Bazhuo and Jialibi (頡利苾) as subordinate khans under Yi'nan—ostensibly to honor them, but hoping to create dissension between them. In 639, when Emperor Taizong commissioned the general Hou Junji to launch a campaign against Gaochang, Yi'nan offered to attack Gaochang at the same time, although Hou's quick conquest of Gaochang appeared to involve no actual Xueyantuo aid.

Conflict of 641
Also in 639, however, a Tang action would begin to lead to a deterioration of the relationship between Tang and Xueyantuo. After Ashina Duobi's capture, Emperor Taizong had settled the Eastern Tujue people who surrendered to Tang within Tang borders, without creating a new khan to govern them. However, after he (Emperor Taizong ) was nearly assassinated by Ashina Duobi's nephew Ashina Jiesheshuai (阿史那結社率) in 639, Emperor Taizong changed his mind and created an Eastern Tujue prince loyal to Tang, Ashina Simo as Qilibi Khan (not to be confused with Yi'nan's son Qilibi), to serve as the new khan of Eastern Tujue, intending to settle his state south of the Gobi Desert to serve as a buffer between Tang and Xueyantuo. Yi'nan was distressed by the development, but initially indicated that he accepted it.

As of 641, Ashina Simo had finally marched north of the Great Wall and settled in at Dingxiang (定襄, in modern Hohhot, Inner Mongolia). Meanwhile, Yi'nan had heard that Emperor Taizong was about to offer sacrifices to heaven and earth at Mount Tai and, believing that the Tang troops would all be with Emperor Taizong, had his son Dadu (大度) launch a major attack on Eastern Tujue, intending to destroy Ashina Simo before Tang could render aid. Ashina Simo withdrew within the Great Wall and took up position at Shuo Prefecture (朔州, roughly modern Shuozhou, Shanxi) and sought emergency aid from Tang. Emperor Taizong sent the general Li Shiji, assisted by the generals Zhang Jian (張儉), Li Daliang (李大亮), Zhang Shigui (張士貴), and Li Xiyu (李襲譽), to attack Xueyantuo. Li Shiji engaged Dadu first and defeated him, forcing him to flee. Meanwhile, Yi'nan had sent an emissary to Emperor Taizong to offer peace with Eastern Tujue, and Li Shiji prevailed over Dadu, Emperor Taizong sent the emissary back with a rebuke for Yi'nan but did not further take actions against Xueyantuo, and thereafter, the relationship between Tang and Xueyantuo officially remained that of lord and vassal, but appeared to be no longer as strong as it formerly was.

Later years of Yi'nan reign
In 642, Yi'nan began an attempt to cement his relationship with Tang by sending his uncle Nishou (泥熟) to Tang to request marriage with one of Emperor Taizong's daughters, offering tributes of horses, mink coats, and a mirror made of amber. Meanwhile, with the Tang general Qibi Heli (契苾何力) -- the chief of the Qibi tribe, a constituent tribe of the Chile as well—being detained in Xueyantuo after he, on a visit back to his tribe, was seized by his own subordinates and taken to Xueyantuo (as his subordinates wanted to submit to Xueyantuo rather than Tang), Emperor Taizong, concerned about Qibi Heli's safety (as Qibi Heli had refused to submit to Xueyantuo, cutting off an ear to show his resolve, causing Yi'nan to nearly execute him), agreed to the marriage proposal, sending the official Cui Dunli to negotiate with Yi'nan the terms, under which Emperor Taizong's daughter Princess Xinxing would marry Yi'nan, in exchange for Qibi Heli's release.

In 643, Yi'nan again sent his nephew Tuli (突利) to offer tributes of 50,000 horses, 10,000 cattle or camels, and 100,000 goats, to serve as bride price. Emperor Taizong welcomed Tuli in a grand ceremony, and Tuli held a great banquet in Emperor Taizong's honor, which Emperor Taizong and his officials personally attended. However, at Qibi's urging, Emperor Taizong was considering renouncing the marriage—initially ordering Yi'nan to personally meet him and Princess Xinxing at Ling Prefecture (靈州, roughly modern Yinchuan, Ningxia) to marry her, believing that Yi'nan would refuse and that he would then have a good excuse to break off the marriage. When Yi'nan agreed to go to Ling Prefecture, Emperor Taizong found another excuse—that the bride price offered had not been all collected (as, in order to gather the livestock making up the bride price, Yi'nan had to collect them from subordinate tribes, and it was taking longer than thought, and the livestock were also dying from having to go through the Gobi) -- to cancel the marriage treaty, despite strong opposition from his official Chu Suiliang, who pointed out that, effectively, he was devaluing his own words. Emperor Taizong rationalized his decision by arguing that if Yi'nan had married a Tang princess, he would have greater legitimacy over the Chile tribes and would be more difficult to control.

Meanwhile, Yi'nan was continuing to attack Eastern Tujue periodically. When Emperor Taizong sent emissaries to try to stop him from doing so, Yi'nan responded:

"How do I not dare to follow the emperor's edict? But the Tujue people are treacherous and should not be trusted. Before the destruction of their state, they invaded China each year and continued to kill thousands of people.  I thought that, after the emperor defeated them, he would make them into slaves and reward them to the Chinese people, but instead the emperor raised them like his own sons and showed much grace to them.  Despite this, Ashina Jiesheshuai rebelled.  They look like humans, but have hearts like beasts, and should not be treated as humans.  I have received much grace from the emperor, and I have nothing to repay him for.  I am willing to kill the Tujue for China."

By the end of 644, the Eastern Tujue people, who were not whole-heartedly supportive of Ashina Simo in the first place, collapsed in light of Xueyantuo threat, fleeing back to Tang territory, and were again settled there. Ashina Simo also went back to Tang and again became a Tang general, ending Tang's attempt to recreate Eastern Tujue as a vassal state. This caused Emperor Taizong to be displeased, and when Yi'nan subsequently sent an emissary to offer tribute to Emperor Taizong, who was at that time deeply into preparation to attack Goguryeo, Emperor Taizong responded, "Go back and tell your khan: My son and I are now about to attack Goguryeo. If he thinks that he can take advantage of this, he is welcome to come!" Yi'nan, fearful of Emperor Taizong's anger, sent another emissary to apologize and offering to assist in the operation against Goguryeo, an offer that Emperor Taizong declined. In 645, after Emperor Taizong had defeated the main Goguryeo forces at Mount Zhubi (駐驆山), near the fortress of Anshi (安市, in modern Anshan, Liaoning), Goguryeo's mangniji (regent) Yeon Gaesomun requested that Yi'nan attack Tang, offering great tributes to him if he did. Yi'nan, fearful of Tang power, did not do so. (However, Emperor Taizong was eventually forced to abandon the campaign anyway after being stymied in his siege of Anshi.)

Yi'nan's death and Xueyantuo's collapse
Yi'nan died in 645. It was described that at this time, Bazhuo, born of Yi'nan's wife, was governing the western part of Xueyantuo, over the Xueyantuo people, while another son of Yi'nan, Yemang (曳莽), who was older but was not born of Yi'nan's wife, was governing the eastern part of Xueyantuo, governing the various tribes. Yemang was said to be violent and disturbed, and also having a bad relationship with Bazhuo. After the funeral, Yemang, fearing that Bazhuo would harm him, left suddenly to return to the eastern part of the khanate. Bazhuo chased him down and killed him, and then took the throne with the title of Jialijulixueshaduomi Khan (or Duomi Khan for short).

Bazhuo, after he took the throne, decided to attack Tang, believing that with Emperor Taizong then on campaign against Goguryeo, that Tang borders would be undefended. However, Emperor Taizong, anticipating the possibility of a Xueyantuo attack, had had the general Zhishi Sili (執失思力) command Tujue soldiers to defend Xia Prefecture (夏州, roughly modern Yulin, Shaanxi). Once Bazhuo attacked, Zhishi Sili and another general, Tian Renhui (田仁會), set a trap to induce Bazhuo to attack Xia Prefecture, and dealt him a defeat once he was at Xia Prefecture. Bazhuo withdrew, but soon attacked Xia Prefecture again.

Briefly after new year 646, Emperor Taizong ordered, in addition to Zhishi and Tian's troops, for troops to be mobilized under the generals Li Daozong the Prince of Jiangxia, Xue Wanche (薛萬徹), Ashina She'er (阿史那社爾), Song Junming (宋君明), and Xue Guwu (薛孤吳), to defend against Bazhuo's attack, which Bazhuo called off after reaching the Great Wall and realizing that Tang forces had been mobilized. In turn, in spring 646, Zhishi and Qiao Shiwang counterattacked, defeating Bazhuo and forcing him to flee, throwing Xueyantuo into a state of confusion.

Meanwhile, it was said that Bazhuo was intolerant and ill-tempered, as well as suspicious. He removed Yi'nan's chief advisors and replaced them with people close to him, which led to the nobles despising him—and he responded by killing a large number of them, throwing the Xueyantuo court into terror. Yaoluoge Tumidu (藥羅葛吐迷度), the chieftain of Huige, then a Xueyantuo vassal, rebelled along with the Pugu (僕骨) and Tongluo (同羅) tribes and dealt Bazhuo a great defeat. Emperor Taizong took the chance to order a major assault against Xueyantuo proper by Li, Ashina, Zhishi, Qibi Heli, Xue Wanche, and Zhang Jian. As the assault was beginning, by chance a Tang officer, Yuwen Fa (宇文法), was serving as an emissary to the Wuluohu (烏羅護) and the Mohe and returning toward Tang, when he encountered the Xueyantuo general Abo (阿波). Yuwen attacked Abo with the Mohe troops with him at the time and defeated Abo—which led to even greater confusion for Xueyantuo, whose people believed that the main Tang army had already arrived. In panic, Bazhuo fled to the vassal Ashide (阿史德) tribe, and when Huige forces heard this, they attacked and killed Bazhuo, slaughtering the Xueyantuo imperial clan members that they could find. Many Xueyantuo generals surrendered to Tang.

The remaining Xueyantuo people briefly supported Yi'nan's nephew Duomozhi as Yitewushi Khan to try to revive Xueyantuo, but neither Tang nor the Chile tribes welcomed this development, and Emperor Taizong sent Li Shiji with an army toward Duomozhi's location—with the instruction to accept Duomozhi's surrender if he wanted to surrender, and to attack if Duomozhi did not. Li Shiji soon arrived at the Khangai, and Duomozhi's assistant Tizhen (梯真) surrendered. Duomozhi fled to the south into the canyon. Li Shiji sent his subordinate Xiao Siye (蕭嗣業) to comfort him, and he surrendered to Xiao. Not all of his subordinates were willing to surrender, however, and Li Shiji attacked them, killing and capturing many of them. Duomozhi was taken to the Tang capital Chang'an and made a Tang general, and Xueyantuo was at its end.