Third conflict in the Goryeo–Khitan War

The Third Goryeo–Khitan War was an 11th-century conflict between the Goryeo dynasty of Korea and the Khitan-led Liao dynasty of China near what is now the border between China and North Korea. The Goryeo–Khitan Wars began in 993 with the first campaign and continued with the second campaign.

After the second Liao campaign against Goryeo, the two sides fought indecisively until 1018, when a large expeditionary army was mobilized by the Liao under the command of Xiao Paiya. The army crossed the Yalu in late 1018 but was ambushed by a superior Goryeo force and suffered severe losses. However the Goryeo army had cut their line of retreat, so Xiao Paiya marched south with the intent of taking Kaesong. They were constantly harried by Korean attacks and forced to retreat. At the Battle of Gwiju, they were encircled and attacked by the Goryeo army, which almost annihilated the Khitan army. According to Korean sources, only a few thousand men managed to retreat to the Liao border.

Aftermath
The next year, the Khitans assembled another large army to march on Goryeo. At this point both sides realized that they could not defeat each other militarily, so in 1020 King Hyeonjong resumed sending tribute, and in 1022 the Khitans officially recognized the legitimacy of King Hyeonjong's reign. In 1022, a Khitan envoy was sent to invest Hyeongjong as king, and when he died in 1031, his successor Wang Heum was also invested by the Liao court as king. Goryeo would remain a Liao tributary, and the relationship between Liao and Goryeo would remain peaceful until the end of the Liao dynasty. According to historian Bielenstein however, Goryeo maintained diplomatic relations with Song rather than break relations, Hyeonjong kept his own reign title, and the two states concluded peace as equals in 1022.