Yan Yan was from Linjiang County, Ba Commandery, which is around present-day Zhong County, Chongqing. He served as a military officer in Ba Commandery under Liu Zhang, the Governor of Yi Province ; Ba Commandery was one of the commanderies in Yi Province. In 211, Liu Zhang invitedthe warlord Liu Bei to lead his troops into Yi Province to help him counter the threat posed by his rival, Zhang Lu, in Hanzhong Commandery. When Yan Yan heard about it, he remarked: "This is equivalent to sitting on an isolated hill and setting a tiger free to protect oneself!" Around 212, conflictbroke out between Liu Zhang and Liu Bei when the latter turned against his host and tried to seize control of Yi Province. In 214, Liu Bei summoned reinforcements from his base in Jing Province to enter Yi Province and assist him in attacking Liu Zhang. Zhang Fei, a general under Liu Bei, led troops to attack Jiangzhou, which was defended by Yan Yan. Zhang Fei defeated Yan Yan, captured him alive, and asked him: "When my army showed up, why did you put up resistance instead of surrendering?" Yan Yan replied: "You people launched an unwarranted attack on my home province. There may be generals in my province who will lose their heads, but there are none who will surrender." Zhang Fei was enraged and he ordered Yan Yan's execution. Yan Yan remained expressionless and said: "If you want to chop off my head, then do it! What's with that outburst of anger?" Zhang Fei was so impressed with Yan Yan's courage that he released him and treated him like an honoured guest. Nothing was recorded in history about Yan Yan from this point onwards.
In ''Romance of the Three Kingdoms''
Yan Yan has a greater role as a character in the 14th-century historical novel Romance of the Three Kingdoms, which romanticises the events before and during the Three Kingdoms period. In Chapter 63 of the novel, as in history, he is defeated and captured by Zhang Fei, who initially wants to execute him but changes his mind and spares him after feeling impressed with Yan Yan's strong sense of loyalty. Zhang Fei also manages to convince Yan Yan to switch his allegiance to Liu Bei. Yan Yan appears again later in Chapters 70 and 71, when he joins Huang Zhong to attack Cao Cao's forces at the Battle of Mount Dingjun.