It makes some sense that the Ming dynasty (AD 1368–1644), following hard on the heels of the traumatic Yuan dynasty (when China was ruled by the Mongols), was characterised by a period of conservative, xenophobic rule. Shānhǎiguān is a perfect example of the Ming mentality. The garrison town and wall here were developed in order to seal off the country from the Manchus, whose ancestors previously ruled northern China during the Jin dynasty (AD 1115–1234). This strategy worked, for a while anyway, but as the Ming grew weaker, the wall’s fatal flaw was exposed.
In 1644, after Chinese rebels seized Běijīng, General Wu Sangui decided to invite the Manchu army through the impregnable pass to help suppress the uprising. The plan worked so well that the Manchus went on to take over the entire country and establish their own Qing dynasty.
An ironic footnote: in 1681 Qing rulers finished building their own Great Wall, known as the Willow Palisade (a large ditch fronted by willow trees), which stretched several hundred miles from Shānhǎiguān to Jílín, with another branch forking south to Dāndōng from Kāiyuán. The purpose, of course, was to keep the Han Chinese and Mongols out of Manchuria.