In 621, with Wang Shichong's state of Zheng under attack by the Tang general
Li Shimin the Prince of Qin (the eventual Emperor Taizong) and in desperate straits, Dou Jiande believed that if Zheng were destroyed by Tang, his own Xia state would be cornered. He therefore launched his army, seeking to save Zheng's capital
Luoyang. Li Shimin engaged him at the
Battle of Hulao, and Dou was captured. Wang then surrendered. The Xia forces considered continuing to resist, but under the leadership of the official Qi Shanxing (), they surrendered Xia territory to Tang. However, subsequently, Dou was executed by
Emperor Gaozu of Tang (Li Shimin's father). The former Xia generals and officials, who had returned to civilian life but who had been often harassed by Tang officials and worried that they would also be executed, gathered secretly and considered rising against Tang rule. After they, led by Gao Yaxian (), were informed by fortunetellers that their leader should be someone named Liu, they first offered their leadership to the general Liu Ya (), who refused (and was then killed by them). They instead offered the leadership to Liu Heita, who was then retired and tending to his garden, and he accepted. In fall 621, they officially rose and captured Zhangnan. The former Xia soldiers gradually came out of retirement and joined him, and Liu offered sacrifices to Dou's spirit, declaring that the Xia forces had risen to avenge him. His uprising was echoed by another agrarian leader,
Xu Yuanlang, who had submitted to Tang but by now was nominally submitting to him. Tang's emperor Gaozu initially sent his cousin Li Shentong () the Prince of Huai'an against Liu, in conjunction with the Tang official
Li Yi the Prince of Yan. Liu defeated Li Shentong, however, at Raoyang (, in modern
Hengshui,
Hebei). Liu then defeated Li Yi as well, and Liu's fame spread through the region. He also entered into an alliance with another agrarian leader,
Gao Kaidao the Prince of Yan, as well as the
Eastern Turks (
Dongtujue). Around the new year 622, Liu defeated Li Xiaochang (, the son of a cousin of Emperor Gaozu) and Li Shiji as well and recovered all of former Xia territory—the region north of the
Yellow River. Emperor Gaozu, now realizing that Liu was a major threat, decided to send Li Shimin and another son,
Li Yuanji the Prince of Qi, to attack Liu. Meanwhile, in spring 622, Liu claimed the title of Prince of Handong. He organized his government in the same manner Dou did, retaining most of former Xia officials and generals. Historians commented that he was even more fierce and resolute in military actions than Dou. He set his capital at
Mingzhou (now Guangfu), the same location as Dou's capital. == Defeat and death ==