Wu Yuanheng was born in 758, during the reign of Emperor Suzong. His family was from Henan Municipality (河南, i.e., the region of the Tang Dynasty eastern capital Luoyang). His great-grandfather Wu Zaide (武載德) was, according to Wu Yuanheng's biographies in the Old Book of Tang and the New Book of Tang, a younger cousin of Wu Zetian, Emperor Suzong's great-grandmother and the female ruler who interrupted Tang rule from 690 to 705 — although, according to the table of the chancellors' family trees in the New Book of Tang, it was Wu Zaide's father Wu Renfan (武仁範) who was a cousin of Wu Zetian's, as Wu Renfan was a son of Wu Zetian's uncle Wu Shiyi (武士逸). Wu Zaide carried the title of Prince of Yingchuan during Wu Zetian's Zhou Dynasty, and at some point served as a prefectural prefect. Wu Yuanheng's grandfather Wu Pingyi (武平一) served as an imperial scholar, while his father Wu Jiu (武就) served as an imperial censor.
Wu Yuanheng passed the imperial examinations, probably during the reign of Emperor Suzong's grandson Emperor Dezong. He then served on the staffs of a number of military governors (Jiedushi), before serving as the magistrate of Huayuan County (華原, near the Tang capital Chang'an). It was said that at the time many generals with accomplishments often, because of their accomplishment, disturbed the people and the officials, and Wu, unable to deal with them, resigned after claiming an illness, spending his time in relaxation, feasts, and poems. However, Emperor Dezong knew of his abilities and recalled him to serve as Bibu Yuanwailang (比部員外郎), a low-level official at the ministry of rites (禮部, Libu). After about a year, he was promoted to be Zuosi Langzhong (左司郎中), one of the chief secretaries at the executive bureau of government (尚書省, Shangshu Sheng). In 804, he was promoted to be deputy chief imperial censor (御史中丞, Yushi Zhongcheng). On one occasion, after he finished making reports to Emperor Dezong and was leaving, Emperor Dezong saw him off and commented to the imperial attendants, "Wu Yuanheng truly has the ability to be a chancellor."
In 805, Emperor Dezong died and was succeeded by his severely ill son Emperor Shunzong. Emperor Shunzong's associate Wang Shuwen became very powerful, and a group of officials gathered around him. Many of those persons were imperial censors serving under Wu, and as Wu despised Wang, he did not treat these associates of Wang's with great respect. Further, when Wu was put in charge of managing the construction of Emperor Dezong's tomb, Wang's associate Liu Yuxi wanted to serve as Wu's deputy but was denied the position. Further, when Wang wanted to draw Wu into his party, Wu resisted. Wang therefore had Wu made a member of the staff of Li Chun the Crown Prince. Li Chun thus got the chance to meet Wu at his investiture as crown prince.
Later in the year, Emperor Shunzong passed the throne to Li Chun (as Emperor Xianzong). Once Emperor Xianzong took the throne, he had Wu Yuanheng restored to the position of deputy chief imperial censor, and it was said that Wu was fair and organized, earning the respect of many. He was soon made the deputy minister of census (戶部侍郎, Hubu Shilang). In spring 807, Wu was made Menxia Shilang (門下侍郎), the deputy head of the examination bureau (門下省, Menxia Sheng), and made a de facto chancellor with the title Tong Zhongshu Menxia Pingzhangshi (同中書門下平章事), along with Li Jifu.
Almost immediately thereafter, Emperor Xianzong was faced with the situation where Li Qi the military governor of Zhenhai Circuit (鎮海, headquartered in modern Zhenjiang, Jiangsu), who had initially offered to come to the capital to pay homage to him, instead requested a deferral. When Emperor Xianzong consulted the chancellors, Wu stated:
Your Imperial Majesty is new to the throne. If Li Qi is allowed to come when he wanted to come and allowed to not come when he did not want to come, all decisions are effectively Li Qi's. How can Your Imperial Majesty expect to command the empire?
Emperor Xianzong agreed and issued an edict summoning Li Qi. Li Qi, receiving the edict, panicked and rebelled, and was soon captured by his own subordinates, delivered to Chang'an, and executed. Later that year, when the general Gao Chongwen, who had in 806 become the military governor of Xichuan Circuit (西川, headquartered in modern Chengdu, Sichuan), offered to resign his position to be moved to a border circuit, Emperor Xianzong looked for an appropriate replacement for Gao but was unable to find one quickly, and so made Wu the military governor of Xichuan, still carrying chancellor title as an honorary title. Wu had previously carried the title of Count of Yaoxiao, and Emperor Xianzong upgraded his title to Duke of Linhuai. It was said that when Gao left the circuit, he carried all kinds of treasures with him; by contrast, Wu lived and governed frugally, and after three years of governance, both the government and the populace were comforted. He also was gentle with the non-Han tribes and stopped his soldiers from harassing them. He was further said to be careful in his actions, and that while he did not spend much time meeting guests, he was nevertheless able to retain a highly capable staff.
In 813, Wu was recalled to Chang'an to again serve as Menxia Shilang and chancellor. It was said that at that time, his fellow chancellors Li Jifu and Li Jiang often disputed with each other, and that he was the moderate between their opinions. After Li Jifu's death in 814, Emperor Xianzong put Wu in charge of managing the campaign against the warlord Wu Yuanji, who then controlled Zhangyi Circuit (彰義, headquartered in Zhumadian, Henan.
Meanwhile, Wu Yuanji's allies Wang Chengzong the military governor of Chengde Circuit (成德, headquartered in modern Shijiazhuang, Hebei) and Li Shidao the military governor of Pinglu Circuit (平盧, headquartered in modern Tai'an, Shandong), were repeatedly pleading on Wu Yuanji's behalf for an imperial pardon, but Emperor Xianzong refused their requests. A group of assassins that Li Shidao had retained persuaded Li Shidao that if Wu Yuanheng were assassinated, the other chancellors would be fearful and would urge an end of the campaign. Li Shidao agreed and sent them to Chang'an to prepare to assassinate Wu Yuanheng. Meanwhile, Wang had sent his officer Yin Shaoqing (尹少卿) to report to Wu Yuanheng; when Yin did, Yin was insolent, and Wu Yuanheng had him expelled from the office of chancellors. Thereafter, Wang submitted petitions defaming Wu Yuanheng.
On July 13, 815, before dawn, Wu Yuanheng was set to go to the palace for a meeting with Emperor Xianzong. As he left his house, suddenly, arrows were fired at his train. His servants all fled, and the assassins seized Wu and his horse, and then decapitated him, taking his head with them. The assassins also attacked another official who favored the campaign, Pei Du, but was unable to kill Pei. The people at the capital were shocked, and imperial guards were assigned to protect chancellors. The officials, for some time, would not dare to leave their houses until dawn. The assassins sent letters to the imperial guards and the governments of Jingzhao Municipality (京兆, i.e., the Chang'an region) and the counties, threatening to kill anyone who dared to pursue them, and it was said that the officials thus did not hunt for them diligently, despite Emperor Xianzong's stern orders. Meanwhile, a group of eight Chengde officers stationed at Chang'an, headed by Zhang Yan (張晏). Wang Chengzong's uncle Wang Shize (王士則), who had become a general in the imperial Shence Army after a dispute with Wang Chengzong, submitted a petition accusing Wang Chengzong of having sent Zhang and the other Chengde officers to kill Wu Yuanheng. Emperor Xianzong had Zhang and the others arrested and interrogated by the mayor of Jingzhao, Pei Wu (裴武), and the imperial censor Chen Zhongshi (陳中師). Under intense interrogation, probably including torture, Zhang and the others confessed to assassinating Wu and were executed. The assassins sent by Li Shidao fled. Emperor Xianzong declared a five-day mourning period for Wu Yuanheng and gave him great posthumous honors.