Emperor Jin Yuandi 晉元帝 (r. 317-322), personal name Sima Rui 司馬睿, courtesy name Jingwen 景文, was the first ruler of the Eastern Jin dynasty 東晉 (317-420). He was a son of Sima Jin 司馬覲 (256-290), Prince of Langya 琅琊. The latter was a son of Sima You 司馬伷 (227-283), the fifth son of Sima Yi 司馬懿 (179-251), while the rulers of the Western Jin dynasty 西晉 (265-316) had been descendants of You's elder brother Sima Zhao 司馬昭 (211-265).
Sima Rui inherited the title of Prince of Langya with the age of 15 sui and was given the title of as supernumerary Cavalier attendant-in-ordinary (yuanwai sanji changshi 員外散騎常侍).
When the Rebellion of the Eight Princes broke out, he decided to side with the regent Sima Yue 司馬越 (d. 311), Prince of Donghai 東海. The regent gave him the title of General Appeasing the East (pingdong jiangjun 平東將軍) and made him supreme commander of the province of Xuzhou (jian Xuzhou zhujun shi 監徐州諸軍事). In this function, he had the duty to protect the city of Xiapi 下邳 (today's Suining 睢寧, Jiangsu).
In the aftermath of the Rebellion, the Xiongnu chieftain Liu Yuan 劉淵 (c. 252-310), who assumed the title of Emperor of (Northern) Han 北漢 (304-317), threatened the Central Plain in northern China. Sima Rui adopted the advice of Wang Dao 王導 (276-339) to take precautions for the protection of the important city of Jianye 建鄴 (today's Nanjing 南京, Jiangsu). The imperial court in Luoyang supported him, gave him the title of General appeasing the east (andong jiangjun 安東將軍) and gave in his hands the temporary (jiajie 假節) command of the troops of the province of Yangzhou (dujian Yangzhou zhujun shi 都督揚州諸軍事).
In autumn 307, Sima Rui took over this command. With the support of the cousins Wang Dao and Wang Dun 王敦 (266-324), he was able to win the confidence of the southern local magnates like Gu Rong 顧榮 (d. 312), Ji Zhan 紀瞻 (253-324) and He Xun 賀循 (260-319) and created a stable political and economic environment in the southeast.
Sima Rui was not willing to risk his gains and in 313 refused to support Emperor Min 晉愍帝 (r. 313-316) against the Xiongnus, even if after he had been given the title of Counsellor-in-chief (chengxiang 丞相) and the supreme command of all imperial armies (da dudu zhongwai junshi 大都督中外軍事).
In 316, the Xiongnu leader Liu Yao 劉曜 (d. 329) sacked Chang'an 長安 (today's Xi'an 西安, Shaanxi), captured Emperor Min and so brought an end to the (Western) Jin dynasty. Emperor Min had no issues, and therefore, Sima Rui decided to take over the throne of the Jin dynasty, but at first only with the title of Prince of Jin 晉王. He chose the reign motto Jianwu 建武 "Arousing martial [spirit]" and made Jianye his residence by changing the city's name to Jiankang 建康. The turmoils in China's north caused many officials and magnates to evade to the south. These were known as "refugees" or "exiles" (qiao 僑). Sima Rui chose one hundred among them to form a kind of central government (known as bai liu yuan 百六掾).
State officials who remained in north China, such as Liu Kun 劉琨 (270-318), Duan Pidi 段匹磾 (d. 321) or Liu Han 劉翰, decided to urge the Prince of Jin to send military relief. A letter signed by no less than 180 persons reached the court in Jiankang.
In 318, Sima Rui assumed the title of emperor and chose the reign motto Taixing 太興 "Great Prosperity". This step is seen as the foundation of the Eastern Jin dynasty. Rui's son Sima Shao 司馬紹 (299-325) was made Heir Apparent (huang taizi 皇太子).
Sima Rui's most important decision in the sphere of cilivian administration was the offer to liberate slaves (tongke 僮客, i.e. dependent farmers, see dianke 佃客, yinke 蔭客) of Southeast China, in case they suffered calamities. Their liberation would increase the number of registered peasants and thus that of persons which were liable for labour corvée (yaoyi 徭役) and tax payment. Yet their former masters, magnates of eminent families (shizu 世族), were enraged over this step.
The government of the early Eastern Jin was in the hands of Wang Dao, who took over civil affairs, and Wang Dun, who was responsible for military matters. A popular saying from that time explained that "the Wangs and the Simas [in this order!] keep together the empire" (Wang yu Ma, gong tianxia 王與馬，共天下). Yet Sima Rui was not fully content of the paramount influence of the two Wangs, and sought to find the support of other high ministers like Liu Wei 劉隗 (273-333), Diao Xie 刁協 (d. 322) or Dai Yuan 戴淵 (271-322), in order to curtail the power of the Wang cousins.
Wang Dun, at that time regional inspector (cishi 刺史) of the province of Jingzhou 荊州, was well aware of this and in 322 decided to raise in rebellion, under the pretext of punishing Liu Wei for high treason. From Wuchang 武昌 (today's Echeng 鄂城, Hubei), Wang Dun advanced to Shitoucheng 石頭城, which was a suburb of Jiankang. The emperor personally took over defense and met the enemy before the city walls, but his army was defeated. Wang Dao secretly supported his cousin. The rebel armies were able to enter the city and killed Dai Yuan and Diao Xi. Liu Wei fled to northern China and offered the Jie 羯-Xiongnu leader Shi Le 石勒 (274-333) his services.
Wang Dun made himself Counsellor-in-chief (chengxiang 丞相) and thus controlled both civilian and military matters. Yet he withdrew to Wuchang and administered the empire from this remote city.
Shortly after, Sima Rui died from illness. He was buried in Mound Pingling 平陵 (close to Nanjing), his posthumous title was Emperor Yuan 元帝 "The Beginner", and his dynastic title Emperor Zhongzong 晉中宗.
He was succeeded by Sima Shao, who is known as Emperor Ming 晉明帝 (r. 322-325).