In 626, Emperor Gaozu's son and major general Li Shimin the Prince of Qin ambushed his brothers Li Jiancheng the Crown Prince and Li Yuanji the Prince of Qi (who supported Li Jiancheng) at the Incident at Xuanwu Gate, and then effectively forced Emperor Gaozu to yield the throne to him (as Emperor Taizong). Wen Yanbo's brother Wen Daya was a supporter of Emperor Taizong, and in fall 626, Emperor Taizong, who had just made peace with Eastern Tujue, made a demand to Ashina Duobi that he return the Chinese people that Tujue had seized and Wen Yanbo. Soon thereafter, Ashina Duobi returned Wen Yanbo, and Emperor Taizong made him the secretary general of the capital prefecture, Yong Prefecture (雍州), and then the assistant minister of civil service affairs. Wen wanted to carry out a major reduction of the civil service system to reduce waste, and this brought many accusations of unfairness from officials as well as criticism that he was overly obsessed with details. However, Emperor Taizong soon made him the deputy head of the legislative bureau, and then made him, in addition, the imperial censor.