Following the successful conquest of Northern Han in 979, Emperor Taizong of Song sought to reclaim the Sixteen Prefectures immediately. He marched his exhausted troops straight into Liao territory toward Youzhou (modern Beijing). However, the Liao reinforced the city, and at the Battle of Gaoliang River, the Song army was crushed by Khitan heavy cavalry. Taizong himself was wounded and escaped only by fleeing on a donkey cart. This defeat proved that the Khitan were a far more formidable foe than the southern kingdoms.
In 986, the Song launched a massive three-pronged offensive known as the Yongxi Campaign. While initially successful, poor coordination and a brilliant Liao counter-offensive led by Empress Dowager Xiao turned the tide. The legendary Song general Yang Ye was left without support at Chenjiagu, where he was captured and later died. Following this second major failure, the Song adopted a defensive posture, constructing elaborate moats and planting massive forests along the border to hinder Khitan cavalry.
The conflict reached its climax in 1004 when Empress Dowager Xiao and Emperor Shengzong led a massive Liao invasion deep into Song territory, reaching the southern bank of the Yellow River at Chanyuan. Facing a critical threat, the Song Emperor Zhenzong was persuaded to go to the front lines to boost morale. A stalemate ensued, and both empires, weary of decades of war, agreed to negotiate. The resulting Treaty of Chanyuan in 1005 established the two rulers as brothers and secured long-term peace in exchange for annual Song payments. This diplomatic settlement allowed both dynasties to flourish for the next century.