First conflict of the Goguryeo–Tang War

The first conflict of the Goguryeo–Tang War started when Emperor Taizong (r. 626–649) of the Tang dynasty led a military campaign against Goguryeo in 645 to protect his ally Silla, and punish Generalissimo Yeon Gaesomun for killing King Yeongnyu. The Tang forces were commanded by Emperor Taizong himself, and generals Li Shiji, Li Daozong, and Zhangsun Wuji.

In 645, after capturing multiple Goguryeo fortresses and defeating large armies in his path, Emperor Taizong appeared poised to march on the capital Pyongyang and conquer Goguryeo, but could not overcome the strong defenses at Ansi Fortress, commanded by Yang Manchun, and withdrew after more than 60 days of battle and unsuccessful siege.

Background
King Yeongnyu planned to execute Yeon Gaesomun, one of the great nobles of Goguryeo, because he considered him a threat. However, Yeon Gaesomun received news of the plot and killed the king along with opposing officials. From that point, Yeon Gaesomun held de facto control of Goguryeo through his puppet King Bojang.

In 642, King Uija of Baekje attacked Silla and captured around 40 strongpoints. In 643, Silla's Queen Seondeok requested aid from Tang because her state was under attack by the Goguryeo–Baekje alliance. Emperor Taizong sent the official Xiangli Xuanjiang (相里玄獎) to demand Goguryeo and Baekje cease their attacks on Silla, but Yeon Gaesomun refused.

Emperor Taizong had a personal ambition to defeat Goguryeo and was determined to succeed where Emperor Yang had failed.

Course
Emperor Taizong used Yeon Gaesomun's murder of the Goguryeo king as the pretext, and began preparations for an invasion in 644. On land, an army of 60,000 Tang soldiers plus an unspecified number of tribal forces gathered at Youzhou, and departed from Yincheng (present-day Chaoyang) under the command of General Li Shiji in April 645. Emperor Taizong personally commanded 10,000 armored cavalry, and would join and reinforce Li Shiji's army during the expedition. At sea, a great fleet of 500 ships transported an additional 40,000 conscripted soldiers and 3,000 military gentlemen (volunteers from the elite of Chang'an and Luoyang) from the Liaodong Peninsula to the Korean Peninsula.

On 1 May, General Li Shiji's troops entered Goguryeo territory, crossing the Liao River farther north and surprising their opponents. On 16 May, they laid siege to Gaimou (Kaemo) Fortress, capturing it in only 11 days, and seizing 20,000 people and 100,000 shi (6 million liters) of grain. General Li Shiji then proceeded toward Liaodong (Yodong) Fortress, and crushed a Goguryeo relief army of 40,000 troops. He was joined by Emperor Taizong and his armored cavalries a few days later, and laid siege to Liaodong Fortress, capturing it too with surprising ease on 16 June with incendiary projectiles and favorable winds, allowing Tang troops to breach the fortress walls.

On 27 June, the Tang army arrived at Baiyan (Baekam) Fortress. However, the Goguryeo commander surrendered the fortress to Tang. Emperor Taizong ordered that the city must not be looted and its citizens must not be enslaved.

On 18 July, the Tang army arrived outside Ansi Fortress. Emperor Taizong was notified of the approach of a large relief army, consisting of Koreans and Malgal, and totaling 150,000 troops. He sent General Li Shiji with 15,000 troops to lure the Goguryeo forces, while another Tang force would secretly flank the enemy troops from behind. On 20 July, the two sides descended into battle and the Tang army came out victorious. Most of the Goguryeo troops dispersed after their defeat. The remaining Goguryeo troops fled to a nearby hill, but surrendered the next day after a Tang encirclement. The Tang forces took 36,800 troops captive. Of these prisoners, the Tang forces sent 3500 officers and chieftains to China, executed 3300 Mohe troops, and eventually released the rest of the ordinary Goguryeo soldiers. However, the Tang army could not breach the Ansi Fortress, defended by the forces of Yang Manchun. Tang troops attacked the fortress as many as six or seven times per day, but the defenders repulsed them each time. As days and weeks passed, Emperor Taizong several times considered abandoning the siege of Ansi to advance deeper into Goguryeo, but Ansi was deemed to pose too great of a threat to abandon during the expedition. Eventually, Tang staked everything on the construction of a huge mound, but it was captured and successfully held by the defenders despite three days of frantic assaults by Tang troops. Furthermore, exacerbated by worsened conditions for the Tang army due to cold weather (and winter approaching) and diminishing provisions, Emperor Taizong was compelled to order a withdrawal from Goguryeo on 13 October, but left behind an extravagant gift for the commander of Ansi Fortress. Tang Taizong's retreat was difficult and many of his soldiers died. Taizong himself tended to the injuries of the Turkic generals Qibi Heli and Ashina Simo, who were both wounded during the campaign against Goguryeo.

Aftermath
In 645, Emperor Taizong founded the Minzhong Temple, the oldest temple in Beijing, to commemorate his soldiers who died in Goguryeo.

Emperor Taizong attacked Goguryeo again in 647 and 648, but was unsuccessful.

Emperor Taizong prepared another invasion in 649, but died in the summer, possibly due to an illness he contracted during his Korean campaigns. Defeating Goguryeo had been an obsession with Emperor Taizong, and after his death, his son Emperor Gaozong continued his ambition.

Yeon Gaesomun died in 666. The Tang–Silla alliance mounted a fresh invasion of Goguryeo in 667, aided by the defector Yeon Namsaeng, and in 668, finally vanquished the divided kingdom, which had been plagued by violent dissension, numerous defections, and widespread demoralization following the death of Yeon Gaesomun.