Wei Yan () (died October 234), courtesy name Wenchang, was a Chinese military general and politician of the state of Shu Han during the Three Kingdoms period of China. Originally a subordinate of the warlord Liu Bei during the late Eastern Han dynasty, Wei Yan rose through the ranks and became a general after Liu Bei seized control of Yi Province (covering present-day Sichuan and Chongqing) in 214. His performance in battle helped him to become a prominent figure in the Shu military in a short period of time. He was later appointed as the Administrator of Hanzhong Commandery and as an Area Commander in 219. Between 228 and 234, he participated actively in the Northern Expeditions led by the Shu regent Zhuge Liang against Shu's rival state, Cao Wei. After Zhuge Liang's death in September 234, Wei Yan was executed by another Shu general, Ma Dai, for alleged treason.
Early life
Wei Yan was from Yiyang Commandery (), which covered parts of present-day Nanyang in southern Henan and parts of northern Hubei. He started his career as a foot soldier under the warlord Liu Bei, probably sometime between 209 and 211 when Liu Bei was in southern Jing Province (covering present-day Hubei and Hunan). Around 212, he followed Liu Bei into Yi Province (covering present-day Sichuan and Chongqing) and served Liu Bei as a personal retainer in a war against Liu Zhang, the Governor of Yi Province (益州牧). Huang Zhong and Wei Yan scored many military exploits during the capture of Guanghan County. Thus, Wei Yan promoted to full general.
The campaign met early success with the quick death of Gao Pei and Yang Huai and the later occupation of the passes, followed by the defeat of Liu Zhang's reinforcements at Fu County. Pang Tong was killed during the siege of Luocheng and the siege became a prolonged one. One year later, Wei Yan and Liu Bei finally captured Luocheng, then surrounded and occupied Chengdu together with Zhuge Liang, Zhang Fei along with others. As Wei Yan has made several contributions in the conquest of Yi Province, Liu Bei promoted him to the rank of General of the Ivory Gate ().
Administrator of Hanzhong
In 217, Liu Bei started the Hanzhong Campaign against his rival Cao Cao.
During his tenure, Wei Yan explained to Liu Bei that he used a strategy called the "double gates" (). The ancient text I Ching described this strategy as a particularly designed fortification which laid numerous military garrisons surrounding the outskirt and trail exits linking to Hanzhong.
Northern Expeditions
thumb|right|upright=1.3|Zhuge Liang's fourth and fifth northern expeditions against Cao Wei
After Liu Bei died in 223, his son Liu Shan succeeded him as the emperor of Shu. In the same year, Liu Shan enfeoffed Wei Yan as a Marquis of a Chief Village ().
In 227, Zhuge Liang, the Imperial Chancellor of Shu, mobilised the Shu military and gathered troops in Hanzhong Commandery in preparation for a large scale invasion of Shu's rival state, Cao Wei (or Wei), where he put Wei Yan in charge of the vanguard division and appointed him as acting Major under the Imperial Chancellor () and acting Inspector of Liang Province (). During this campaign, Wei Yan always requested to lead a separate detachment of 10,000 troops, take a different route through the Ziwu Valley () and rendezvous with the Shu main army at Tong Pass (; in present-day Tongguan County, Shaanxi).
Wei Yan argued that the Ziwu Valley and its resources could support the Shu army's operations at least for a week.
Later in 230, during the Ziwu Campaign, Wei Yan led some troops towards Yangxi (; southwest of present-day Wushan County, Gansu) and engaged the Wei forces led by and Guo Huai and Fei Yao, where Wei Yan managed to inflict a heavy defeat to them. During the same year, he also assisted another Shu general Wu Yi in attacking Nan'an Commandery (; southeast of present-day Longxi County, Gansu) where they scored another victory against a Wei army led by Fei Yao.
During the fourth campaign in 231, Wei Yan was also involved in the Battle of Mount Qi when he, together with the Shu generals Gao Xiang and Wu Ban, scored a major victory against the Wei army led by Sima Yi, during which they killed 3,000 Wei soldiers and seized 5,000 sets of armour and 3,100 crossbows. Sima Yi was forced to retreat back to his camp. Zhang He, a veteran Wei general, was also killed in battle during this conflict.
Wei Yan then asked Fei Yi to assist him in making arrangements for part of the Shu army to remain behind and continue with the campaign, while the rest would retreat back to Shu. He then sent his subordinate to meet Yang Yi and the others, but was shocked to discover that all units were preparing to retreat in accordance with Zhuge Liang's final orders.
Wei Yan was left with only his son(s) and a few followers, and they fled towards Hanzhong Commandery. Yang Yi ordered Ma Dai to give chase. Yang Yi trampled on Wei Yan's head and said:
