He hailed from Qi 祁 in the commandery of Taiyuan 太原 (modern Qixian 祁縣, Shanxi), where his family had exerted local governorship for generations. He was a well-educated person but was also an excellent rider and archer. As a young man he obtained his first office in the commandery, but the eunuch Zhao Jin 趙津 had slandered and arrested him. Later on he was made attendant censor (shiyushi 侍御史).
During the reing of Emperor Ling 漢靈帝 (r. 167-189), when the rebellion of the Yellow Turbans 黃巾 burst out, Wang Yun was made regional inspector (cishi 刺史) of the province of Yuzhou 豫州. His excellent connections made it possible that one of the leaders of the Yellow Turbans, Zhang Rang 張讓, became a whistleblower and reported the tactical plans of the rebels. Yet for some time, Wang Yun was put in prison because of his collaboration with the defector, but he was released and reinstated in his position. Another charge of high treason endangered him with the death penalty, but General-in-Chief (da jiangjun 大將軍) He Jin 何進, Defender-in-chief (taiwei 太尉) Yuan Wei 袁隗 and Minister of Education (situ 司徒, see Three Dukes 三公) Yang Ci 楊賜 pledged to pardon him.
Escaped from prison, Wang Yun changed his name and his for some time in Chenliu 陳留. After the death of Emperor Ling, He Jin - meanwhile advanced to regent for the Infant Emperor Liu Bian 劉辯 (r. 189 CE) - hired competent advisors, and Wang Yun was made palace gentleman for service (congshi zhonglang 從事中郎), later metropolitan magistrate (yin 尹) of Henan 河南. On the accession to the throne of Emperor Xian 漢獻帝 (r. 189-220) he was promoted to Chamberlain for the Imperial Stud (taipu 太僕) and was then made Director of the Imperial Secretariat (shangshu ling 尚書令).
In 190 he was concurrently made Minister of Education as successor of Yang Biao 楊彪. After the great turmoil of the massacre of the eunuchs, when general Dong Zhuo 董卓 took over power and forced the court to move to the ancient capital Chang'an 長安 (modern Xi'an 西安, Shaanxi) Wang Yun selected the most important books from the imperial library to secure them on the imperial move to the the far west. But unfortunately, not only the main capital Luoyang 洛陽 (modern Luoyang, Henan) was devasted, but also Chang'an later suffered the feat of ruin.
While Dong Zhuo remained in Luoyang, Wang Yun was the person who in fact managed all court affairs. Because of his loyalty he was rewarded with the title of Marquis of Wen 溫侯. Feigning to support the usurper Dong Zhuo, he secretly planned with metropolitan commander (sili xiaowei 司隸校尉) Huang Wan 黃琬 to kill the potentate. Together with general Lü Bu 呂布, the conspirators killed Dong Zhuo in Chang'an. Wang Yun was then the sole potentate at the court, and the factual regent.