Emperor Wenzong ascended the throne after his elder brother, Emperor Jingzong was murdered by the corrupt eunuch Wang Shoucheng after reigning less than four years. Ever since the An Lushan rebellion in the middle of the eighth century, corrupt eunuchs had held sway over the government. Wenzong's tenure was plagued with political infighting between eunuch factions and ministers loyal to the emperor. Aided by officials such as Li Xun and Zheng Ju, Wenzong attempted to remove all corrupt eunuchs from power. This resulted in a plot hatched by Li Xun to ambush and kill all the corrupt eunuchs while they were invited to a gathering one day in 835. The plot was finally discovered and Wenzong was held hostage and put under house arrest while Li Xun and Zheng Ju was executed.
Wenzong died in the first month of 840 after five years of house arrest and reigning for 13 years and one month perhaps lamenting the fact that he was an emperor but was controlled by his servants. He was succeeded by his younger brother.
Emperor Wenzong issued an imperial decree, stating 's , Pei Min's swordplay and Li Bai's poetry as the "Three Wonders of the Great Tang Empire".