He hailed from Jingling 竟陵 (modern Qianjiang 潛江, Hubei) and was made inner gentleman (zhonglang 中郎) when he was still in his youth. He climbed the ladder of official career from magistrate (ling 令) of Luoyang 洛陽 to regional inspector (cishi 刺史) of Jizhou 冀州 and governor (taishou 太守) of the commandery of Nanyang 南陽 and was finally appointed Chamberlain for the Imperial Clan (zongzheng 宗正) and Chamberlain for Ceremonials (taichang 太常).
When the central government slowly disintegrated during the reign of Emperor Ling 漢靈帝 (r. 167-188), he asked being transferred to a local office, he was made regional governor (mu 牧) of Yizhou 益州 and given the title of Marquis of Yangcheng 陽城侯. In this position he suppressed local disturbances by groups of the Yellow Turban rebels 黃巾起義 and also ensured the obedience of the local gentry. He had the heads of some influential families executed, like Wang Xian 王咸, Li Quan 李權 and Jia Long 賈龍.
Liu assembled a large army and participated in the campaigns suppressing the last adherents of the warlord Dong Zhuo 董卓 who had forced the young emperor to move the capital from Luoyang 洛陽 to Chang'an 長安 (modern Xi'an). As General Marching Against the West (zhengxi jiangjun 征西將軍), Liu Yan undertook a campaign against Li Jue 李傕. During this war he was accompanied by his sons Liu Fan 劉範 and Liu Dan 劉誕. His strategy failed, partly also because he had deprived himself of all support by the local gentry, and he was defeated, his sons were killed, and Liu Yan himself died soon.