The Jin–Song Wars were a series of conflicts that took place in the 12th and 13th centuries between the Jurchen Jin dynasty and the Han Chinese Song dynasty. The Jin invaded the Song in 1125 and captured the Song capital of Kaifeng in 1127, imprisoning Emperor Qinzong and Huizong (pictured). The Jin conquered northern China and remnants of the Song retreated to southern China, relocating the capital to Hangzhou. A treaty ended the war in 1142 and settled the boundary along the Huai River. Prince Hailing invaded the Song in 1161, but lost at Caishi and was assassinated shortly after. A Song invasion of the Jin motivated by revanchism in 1206–08 and a Jin invasion of the Song in 1217–24 were both unsuccessful. The Song allied with the Mongols in 1233, and jointly captured the last refuge of the Jin emperor in 1234, the year the Jin collapsed. The wars between the Song and Jin gave rise to an era of technological, cultural, and demographic changes in China. The Jin adopted the political and cultural institutions of past Chinese dynasties, gunpowder weapons like the fire lance were introduced, and the Song resettled and rebuilt their government in southern China.