He hailed from Fufeng 扶風 (modern Xingping 興平, Shaanxi) and came from a family a lot of whose members had served as palace eunuchs. During the reign of the usurper Wang Mang 王莽 (r. 8-23 CE) he served as local inspector (duyou 督郵) in a commandery but had to escape punishment because of some offense he had committed. He was pardoned but stayed in the garrison of Beidi 北地 where he had fled to, was able to grab the power over that region and was also appointed governor (during the Wang Mang reign called dayin 大尹) of Xincheng 新城 (the contemporary name of Hanzhong 漢中).
When the empire of Wang Mang disintegrated, Ma Yuan became a follower of the warlord of the western region, Wei Ao 隗囂, who made him general (suide jiangjun 綏德將軍). In 28 CE he travelled to the newly established court of Emperor Guangwu 漢光武帝 (r. 25-57 CE) in Luoyang 洛陽 (modern Luoyang, Henan). He also accompanied Wei Ao's son Wei Xun 隗恂 to Luoyang when Wei Xun served as a hostage to ensure the loyalty of his father to the Han court. Ma Yuan soon lost his importance for the warlord Wei Ao and lived a private life with his retainers, settling down in the ancient imperial hunting park of Shanglin 上林.
Emperor Guangwu, after having secured his rule, began consulting Ma Yuan as a military advisor. His first plan was to defeat Wei Ao, who controlled the northeast. In 35 CE Ma Yuan was appointed governor (taishou 太守) of the commandery of Longxi 隴西, where he was entrusted with the campaign against the Western Qiang 西羌 tribes and the Qiang of Xianling 先零羌. Ma Yuan so cleared the way to the west along the Silk Road and was given the title of eader of the court gentlemen brave as tigers (huben zhonglangjiang 虎賁中郎將).
In 41 CE the sisters Trưng Thắc 徵側 (Chinese reading Zheng Ze) and Trưng Nhị 徵貮 (Zheng Ni) stirred up rebellion in the commandery of Jiaozhi 交趾, and the native Yi 夷 and Man 蠻 tribes of Jiuzhen 九真 and Rinan 日南 responded the insurgence (all located northern part of modern Vietnam). Ma Yuan was sent out to put down the rebellion. For his victory he was given the title of Marquis of Xinxi 新息侯.
During all his military campaigns, Ma Yuan tried not to harass the local population and furthermore supported them by having built the necessary infrastructure, like city walls or canals. Among the Yue tribes 越 of the south he was also known for sincerity to keep negotiated contracts. His last campaign was that against the Man tribes of Wuling 武陵 and Wuxi 五溪 in 49 CE.
He died from a pestilence in the military camp at Hutou 壺頭. Even after his death, he was slandered by Liang Song 梁松, gentleman of the Yellow Gate (huangmenlang 黃門郎) and posthumously deprived of his seal of marquis, so that his son could not inherit title and land. His daughter became the main consort of Emperor Ming 漢明帝 (r. 57-75 CE), but the emperor prohibited her relatives to be granted any offices at the court or any estates within the empire. Only in 78 CE Emperor Zhang 漢章帝 (r. 76-88 CE) lifted the ban and bestowed Ma Yuan posthumously the title of Marquis Zhongcheng 忠成侯 "the Loyal and Sincere".