Wei Yan was born in Yiyang Commandery in Jing Province, the lands of Governor Liu Biao. Wei Yan served under Liu Biao as one of his generals, and he fought against Sun Jian's invasion of Xiangyang in 192 AD along with Huang Zhong, an older warrior who became a close frien of Wei Yan. Wei Yan later served under Prefect of Changsha Han Xuan, who was a vassal of the powerful central warlord Cao Cao. In 208 AD, Liu Bei and an army of troops led by Zhuge Liang invaded Jing Province and seized Lingling, Guiyang, and Wuling quickly. However, Wei Yan, Huang Zhong, and Yang Ling were dispatched to guard the gates. Liu Bei's general Guan Yu killed Yang Ling and defeated Huang Zhong and Wei Yan. Infuriated, Han Xuan prepared to execute Huang Zhong himself, but Wei Yan cut Han Xuan down and both Wei Yan and Huang Zhong surrendered to Liu Bei, becoming generals.
Wei Yan and Huang Zhong served together again in the 212-215 AD Battle of Yi Province, where Liu Bei fought against Prefect Liu Zhang to gain control of the large Yi Province in the westermost reaches of the Later Han. Wei Yan and Huang Zhong together took part in the Battle of Luo Castle, where Wei Yan's foolishness led him to fall into a trap, and Liu Bei's strategist Pang Tong was mortally wounded by Zhang Ren while trying to rescue him. Wei Yan made up for his overzealousness by aiding in the conquest of the capital of Chengdu in 214 AD.
When Zhuge Liang prepared to invade Cao Cao's lands in 215 AD, Wei Yan, Huang Zhong, Zhang Fei, Zhao Yun, Ma Chao, and Yue Ying served as his major commanders. In the Battle of Hanzhong, Wei Yan distinguished himself in the fight against Cao Cao's general Sima Yi, who commanded Cao Cao's forces in the battle. After the battle ended in 218 AD, Wei Yan was dispatched north to guard Hanzhong.
In 225 AD, after the Kingdom of Shu Han was founded (Liu Bei created the kingdom shortly before his death in 223 AD), the now-Chancellor Zhuge Liang dispatched Wei Yan, Wang Ping, Zhang Yi, Zhao Yun, and Guan Suo to Nanzhong, a jungle region of southern Yi Province that was inhabited by the Nanman tribes, who rose in rebellion under Great King Meng Huo. With 500,000 troops, the Shu army faced 100,000 Nanman, and Wei Yan performed well in the campaign. Zhuge Liang would later use the same generals in Zhuge Liang's Northern Expeditions from 227-234 AD. Wei Yan killed the Cao Wei general Wang Shuang at the Battle of Chencang in 229 AD and fought well in the Battle of Mt. Qi and the Battle of Wuzhang Plains.
Wei Yan's downfall came shortly after Zhuge Liang died at the Wuzhang Plains. Yang Yi ordered the Shu army to retreat, but Wei Yan (who was to serve as the rearguard) refused to follow his orders, and Wei Yan and Fei Yi both remained behind. Later, Wei Yan marched ahead of the army and began to destroy the gallery roads (plank roads down the mountains) on the way to Chengdu to force the army to remain north. Both Wei Yan and Yang Yi wrote to Emperor Liu Shan, accusing each other of treason, and in the end, Dong Yun and Jiang Wan convinced Liu Shan that Wei Yan was the traitor.
Yang Yi ordered his army to march day and night to catch up to Wei Yan, while cutting down trees to rebuild the gallery roads. With only his son and a few followers, Wei Yan withdrew to Hanzhong, with Yang Yi sending Ma Dai to pursue. Ma Dai gave chase and decapitated Wei Yan after a short duel, and he brought his head to Chengdu, after Yang Yi trampled it out of spite.