Yuan Zhen (; 779 – September 2, 831Academia Sinica Chinese-Western Calendar Converter .), courtesy name Weizhi (), was a Chinese novelist, poet, and politician of the middle Tang dynasty. In prose literature, Yuan Zhen is particularly known for his work Yingying's Biography, which has often been adapted for other treatments, including operatic and musical ones. In poetry, he is remembered for the inclusion of some of his poems by popular anthologies, his verses on exotic topics (such as the former Liangzhou), and for being part of the group of "New Yuefu" poets, which often used poetry as a form of expression and protest, but one potentially subtle enough to avoid the likely repercussions of more direct criticism. The poetic circle in which Yuan Zhen was involved included Bai Juyi, among others. Politically Yuan Zhen was briefly chancellor, during the reign of Emperor Muzong.

A native of Luoyang, Yuan Zhen was a descendant of Northern Wei's imperial family. He lost his father at the age of seven and moved to Fengxiang (), near today's Baoji, Shaanxi with his mother Lady Zheng (). Yuan began his writings at the age of fifteen. He was a member of Bai Juyi's literary circle and a key figure in the ancient literature revival. He was a friend of Bai Juyi and also of Xue Tao, a courtesan and famous poet who might have been his lover. Bai Juyi and Yuan Zhen made a "Green Mountain pact" to retire together as Taoist recluses once they had accumulated enough funds, but Yuan's untimely death kept them from achieving that dream.Hinsch, Bret. (1990). Passions of the Cut Sleeve. University of California Press. p. 81 In 813, Yuan wrote a grave inscription for Du Fu, which contains some of the earliest known praise for his predecessor's works.

Background Yuan Zhen was born in 779, around the time of Emperor Dezong's ascension to the throne.Old Book of Tang, vol. 166.Old Book of Tang, vol. 12. He was a 10th-generation descendant of Tuoba Shiyiqian, the grandfather of Northern Wei's founder Emperor Daowu, who was posthumously honored Emperor Zhaocheng after Northern Wei's founding.New Book of Tang, vol. 75. That Tuoba Shiyijian was Emperor Daowu's grandfather is pursuant to most traditional accounts, but there has been some doubt raised on whether Tuoba Shiyijian was actually Emperor Daowu's father. See Emperor Daowu's article for more details. Yuan Zhen's male ancestor line was renamed Yuan, from Tuoba, when Emperor Xiaowen changed Xianbei names to Han names in 496.Zizhi Tongjian, vol. 140. Subsequently, ancestors of Yuan Zhen's served as officials of the Sui dynasty and Tang dynasty. His grandfather Yuan Fei () served as a county secretary general, while his father Yuan Kuan () served as a low-level official at the ministry of justice, as well as secretary to an imperial prince.

Yuan Kuan died when Yuan Zhen was seven, and Yuan Zhen was raised by his mother Lady Zheng, who was considered an intelligent woman. As the household was poor, she did not send Yuan Zhen to school, but taught him to read and write herself. It was said that Yuan became capable of writing at age eight, and at age 14 passed the imperial examination for understanding two Confucian classics. At age 23, he was made a copyeditor at the Palace Library.

During Emperor Xianzong's reign In 806, when Yuan Zhen was 27, during the reign of Emperor Dezong's grandson Emperor Xianzong, Yuan underwent a special imperial examination before Emperor Xianzong dealing with strategic thinking, and when the list of 18 examinees who passed the examination was announced, Yuan was ranked first — in a group that included such individuals as Bai Juyi, Dugu Yu (), Xiao Mian, and Shen Chuanshi (). As a result, Yuan was made You Shiyi (), a junior advisor at the legislative bureau of government ().Zizhi Tongjian, vol. 237.

Yuan had an outspoken personality, and after being put into an advisorial post, he started submitting suggestions to Emperor Xianzong. In particular, because the officials Wang Shuwen and Wang Pi, who dominated the court of Emperor Xianzong's father Emperor Shunzong — who had previously served as Emperor Shunzong's staff members while Emperor Shunzong was crown prince — were at that time denounced as frivolous and power-hungry, Yuan submitted an essay detailing what he saw as qualifications that the crown prince's and other imperial princes' staff members should have, and Emperor Xianzong was impressed upon reading it. Yuan further submitted proposals involving the defense of the northwestern borders with the Tibetan and Uyghur Empires. Emperor Xianzong, in response, summoned him and requested opinions on strategies to take there. As a result, though, the ruling officials at the time were jealous of Yuan, and they had him sent out of the capital Chang'an to serve as the sheriff of Henan County (), one of the two counties making up the eastern capital Luoyang. Yuan subsequently left governmental service for some time while observing a mourning period after his mother's death. Once the mourning period was over, he was recalled to governmental service, to serve as Jiancha Yushi (), a mid-level imperial censor.

In 809, Yuan was on a mission to Dongchuan Circuit (東川, headquartered in modern Mianyang, Sichuan), when he submitted accusations that the deceased former military governor (Jiedushi) of Dongchuan, Yan Li (), had collected taxes illegally and improperly seized the property of 88 households. As a result, the seven prefectural prefects who served under Yan were all punished. However, among the ruling officials, there were those who had deep friendships with Yan, and as a result of this incident, Yuan was sent out of the capital to serve at Dongtai (东台), the Luoyang branch of the office of the imperial censors. While at Luoyang, he continued to pursue various officials for misconduct, including the caning of a county magistrate by the governor of Zhexi Circuit (浙西, headquartered in modern Zhenjiang, Jiangsu), Han Gao (), leading to the magistrate's death, and the improper use of imperial messenger posts by the military governor of Wuning Circuit (武寧, headquartered in modern Xuzhou, Jiangsu), Wang Shao (), to host the casket of the recently deceased eunuch monitor of the Wuning army. Meanwhile, when the mayor of Henan Municipality (i.e., the Luoyang region, not only the two counties), Fang Shi (), was accused of improper conduct, Yuan issued an order suspending Fang from office pending investigations. However, after investigations, Fang was only punished by being stripped of one month of salary, and Yuan was recalled to Chang'an.New Book of Tang, vol. 174. While stopping at the imperial messenger post at Fushui (敷水, in modern Weinan, Shaanxi), Yuan got into a dispute with an imperial eunuch messenger — variously reported as either Liu Shiyuan () (by the Old Book of Tang) or Qiu Shiliang (by the New Book of Tang), in which the eunuch, as a result of the dispute, hit Yuan's face and injured him — Emperor Xianzong ruled that Yuan had overstepped his authorities as censor and demoted him to serve as the logistics officer at Jiangling Municipality (江陵, in modern Jingzhou, Hubei), despite defenses submitted on his behalf by Li Jiang, Cui Qun, and Bai.Zizhi Tongjian, vol. 238.

While at Jiangling, Yuan wrote many poems, and his style and Bai's were both popular and referred by the populace as Yuanhe Style () — Yuanhe being Emperor Xianzong's era name. The eunuch monitor of Jingnan Circuit (荊南, headquartered at Jiangling), Cui Tanjun (), was impressed by Yuan's talents and did not treat him as a subordinate, but rather with great respect; he also often collected Yuan's poems and recited them. Meanwhile, sometime thereafter, Yuan was made the military advisor to the prefect of Tong Prefecture (通州, in modern Nantong, Jiangsu), while Bai was made the military governor of Jiang Prefecture (江州, in modern Nanchang, Jiangxi). Despite the distance between the two, they often wrote poems to each other, which often ran 30 to 50 lines, sometimes up to 100 lines. The people of the Yangtze River region became impressed by their poems and often read and studied them. Many of Yuan's poems showed his sadness at being exiled from the capital.

In 819, by which time Yuan was serving as the secretary general of Guo Prefecture (虢州, in modern Sanmenxia, Henan), he was recalled to Chang'an to serve as Shanbu Yuanwailang (), a low-level official at the ministry of rites (禮部, Libu). Then-chancellor Linghu Chu, himself a talented writer, had long been impressed by Yuan's literary abilities, requested that he submit his writings to Linghu. Yuan did so, and the writings impressed LInghu greatly, comparing him to the Liu Song dynasty poets Bao Zhao () and Xie Lingyun. Meanwhile, Emperor Xianzong's son and crown prince Li Heng, who had heard his concubines recite Yuan's poetry and referring to Yuan as "Savant Yuan" (), was impressed.Zizhi Tongjian, vol. 241.

During Emperor Muzong's and Emperor Jingzong's reigns In 820, by which time Li Heng was emperor (as Emperor Muzong), Cui Tanjun was recalled to Chang'an, and he offered to Emperor Muzong, as a gift, a collection of over 100 poems by Yuan Zhen. Emperor Muzong was pleased, and asked Cui where Yuan was at that point, and Cui replied that Yuan was serving in an office lacking authority. That same day, Emperor Muzong promoted Yuan to be Cibu Langzhong (), a supervisorial official at the ministry of rites, and further put him in charge of drafting edicts for Emperor Muzong. However, because this was an irregular promotion, Yuan was looked down by his colleagues. On one occasion, when many imperial officials were gathering to eat melons, there were flies which gathered on the melons. Wu Ruheng () waved his fan to chase away the flies, and made the double entendre, "Where did you come from? Why did you come here?" This caused many of Wu's colleagues to be shocked and lose composure, but Wu did not. Nevertheless, Yuan's poetry continued to become increasingly popular at Chang'an, such that the people were rushing to learn it. Soon thereafter, Yuan was made chief imperial scholar (翰林承旨學士, Hanlin Xueshi) as well as Zhongshu Sheren (), a mid-level official at the legislative bureau. Because of the friendship that Yuan had with Cui, the other eunuchs were also trying to become friendly with Yuan, particularly one of the directors of palace communications (Shumishi), Wei Hongjian ().