The Goguryeo-Tang War occurred from 645 to 668 and was fought between the Goguryeo kingdom and Tang empire. During the course of the war the two sides allied with various other states. Goguryeo successfully repulsed the invading Tang armies during the first Tang invasions of 645-648. After conquering Baekje in 660, Tang and Silla armies invaded Goguryeo from the north and south in 661, but were forced to withdraw in 662. In 666, Yeon Gaesomun died and Goguryeo became plagued by violent dissension, numerous defections, and widespread demoralization. The Tang-Silla alliance mounted a fresh invasion in the following year, aided by the defector Yeon Namsaeng. In late 668, exhausted from numerous military attacks and suffering from internal political chaos, the kingdom of Goguryeo and the remnants of Baekje army succumbed to the numerically superior armies of the Tang Dynasty and Silla.
The war marked the end of the Three Kingdoms of Korea period which had lasted since 57 BCE. It also triggered the Silla-Tang War during which the Silla kingdom and the Tang empire fought over the spoils they had gained.
The Silla kingdom had made numerous requests to the Tang court for military assistance against Goguryeo, which the Tang court began to consider not long after they had decisively defeated the Göktürks in 628. At the same time, however, Silla was also engaged in open hostilities with Baekje in 642. A year before (641), King Uija had assumed the throne of Baekje. In 642, King Uija attacked Silla and captured around 40 strongpoints. Meanwhile, in 642, the military dictator Yeon Gaesomun murdered over 180 Goguryeo aristocrats and seized the Goguryeo throne. He placed a puppet king onto the throne after killing the king in 642. These newly formed governments in Baekje and Goguryeo were preparing for war and had established an mutual alliance against Tang and Silla.
Emperor Taizong used Yeon Gaesomun's murder of the Goguryeo king as the pretext for his campaign and started preparations for an invasion force in 644. General Li Shiji commanded an army of 60,000 Tang soldiers and an undisclosed number of tribal forces. They would gather at Youzhou. Emperor Taizong commanded an armored cavalry of 10,000 strong. His cavalry would eventually meet up and join General Li Shiji's army during the expedition. A fleet of 500 ships would also transport an additional 40,000 conscripted soldiers and 3,000 military gentlemen (volunteers from the elite of Chang'an and Luoyang). This fleet would sail from the Liaodong Peninsula to the Korean Peninsula.
In April 645, General Li Shiji's army departed from Yincheng (present-day Chaoyang). On 1 May, they crossed the Liao River into Goguryeo territory. On 16 May, they laid siege to Gaimou (Kaemo), which fell after only 11 days, capturing 20,000 people and confiscating 100,000 shi (6 million liter) of grain.
Afterwards, General Li Shiji's army advanced to Liaodong (Ryotong). On 7 June 645, they crushed a Goguryeo army of 40,000 troops strong, who were sent to the city to relieve the city from the Tang siege. A few days later, Emperor Taizong's cavalry arrived at Liaodong. On 16 June, the Tang army successfully set Liaodong ablaze with incendiary projectiles and breached its defensive walls, resulting in the fall of Liaodong to the Tang forces.
The Tang army marched further to Baiyan (Paekam) and arrived there on 27 June 645. However, the Goguryeo commanders surrendered the city to the Tang army. Afterwards, Emperor Taizong ordered that the city must not be looted and its citizens must not be enslaved.
On 18 July 645, the Tang army arrived at Ansi Fortress. A Goguryeo army, including Mohe troops, were sent to relieve the city. The reinforcing Goguryeo army totaled 150,000 troops. However, Emperor Taizong sent General Li Shiji with 15,000 troops to lure the Goguryeo forces. Meanwhile, 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 they 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 into the city of Ansi. This city was 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 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 October 13, but left behind an extravagant gift for the commander of Ansi Fortress. Tang Taizong's retreat was difficult and many of his soldiers died.
Under Emperor Gaozong's reign, the Tang empire formed a military alliance with the Silla kingdom. When Goguryeo and Baekje attacked Silla from the north and west respectively, Queen Seondeok of Silla sent an emissary to the Tang empire to desperately request military assistance. In 650, Emperor Gaozong received a poem, written by Queen Jindeok of Silla, from the princely emissary Kim Chunchu (who would later accede the Silla throne as King Muyeol). In 653, Baekje allied with Yamato Wa. Even though Baekje was allied with Goguryeo, the Han River valley separated the two states and was a hindrance in coming to each other's aid in time of war.King Muyeol assumed the Silla throne in 654. Between 655 and 659, the border of Silla was harassed by Baekje and Goguryeo; Silla therefore requested assistance from Tang. In 658, Emperor Gaozong sent an army to attack Goguryeo but was unable to overcome Goguryeo's stalwart defenses.Kim Chunchu suggested to Tang that the Tang-Silla alliance first conquer Baekje, breaking up the Goguryeo-Baekje alliance, and then attack Goguryeo.
In 660, the Tang empire and the Silla kingdom sent their allied armies to conquer Baekje. The Baekje capital Sabi fell to the forces of Tang and Silla. Baekje was conquered on 18 July 660, when King Uija of Baekje surrendered at Ungjin. The Tang army took the king, crown prince, 93 officials, and 20,000 troops as prisoner. The king and crown prince were sent as hostages to the Tang empire. The Tang empire annexed the territory and established five military administrations to control the region instead of Silla, which they painfully accepted. In a final effort, General Gwisil Boksin led the resistance against Tang occupation of Baekje. He requested military assistance from their Yamato allies. The Tang fleet, comprising 170 ships, advanced towards Chuyu and encircled the city at the Baekgang River. As the Yamato fleet engaged the Tang fleet, they were attacked by the Tang fleet and were destroyed. In 663, the Baekje resistance and Yamato forces were annihilated by the Tang and Silla forces at the Battle of Baekgang. Subsequently, Prince Buyeo Pung of Baekje and his remaining men fled to Goguryeo.
After the conquest of Baekje in 660, the Tang and Silla forces planned to invade Goguryeo. In 661, the Tang forces set off to Goguryeo. As the Tang army advanced with 350,000 troops, Silla was requested to provide only supplies during this expedition. In 662, Yeon Gaesomun defeated General Pang Xiaotai at the Battle of Sasu. The Tang army besieged Pyongyang, Goguryeo's capital, for several months until February 662, when it had to withdraw from the campaign due to the harsh winter conditions, and the defeat of its subsidiary force.
In 666, the Goguryeo dictator Yeon Gaesomun died and an internal struggle between his sons for power broke out. Goguryeo was thrown into chaos and weakened by the succession struggle among his sons and younger brother, with his eldest son (and successor) defecting to Tang and his younger brother defecting to Silla. Yeon Gaesomun's death paved the way for a fresh invasion by Tang and Silla in 667, this time aided by Yeon Gaesomun's oldest son. The violent dissension resulting from Yeon Gaesomun's death proved to be the primary reason for the Tang-Silla triumph, thanks to the division, defections, and widespread demoralization it caused. The alliance with Silla also proved to be invaluable, thanks to the ability to attack Goguryeo from opposite directions, and both military and logistical aid from Silla. In 668, the Tang and Silla forces besieged and conquered Pyongyang, which led to the conquest of Goguryeo. Over 200,000 prisoners were taken by the Tang forces and sent to Chang'an.
In 669, the Tang government established the Protectorate General to Pacify the East to control the former territories of Goguryeo. A subordinate office was in Baekje. By the end of the war, the Tang empire had taken control over the former territories of Baekje and Goguryeo and tried to assert dominion over Silla. Large parts of the Korean Peninsula were occupied by the Tang forces for about a decade.
However, the Tang occupation of the Korean Peninsula proved to be logistically difficult due to shortage of supplies, which Silla used to provide previously. Furthermore, Emperor Gaozong was ailing, so Empress Wu took a pacifist policy, and the Tang empire was diverting resources towards other priorities. This situation favored Silla, because soon Silla would have to forcibly resist the imposition of Chinese rule over the entire peninsula. War was imminent between Silla and Tang.