He hailed from Chengdu 成都 (modern Chengdu, Sichuan) and as a young man was expert in books as well as in sword fighting. During the reign of Emperor Jing 漢景帝 (r. 157-141 BCE) he was appointed mounted attendant-in-ordinary (wuji jiangjun 武騎常侍). He tried to present some of his rhapsodies at the court but was disappointed that Emperor Jing did not love this literary genre, and retired.
He travelled to the princedom of Liang 梁, where he became friends with the attendant clerks (wenxue shi 文學侍) Zou Yang 鄒陽, Yan Ji 嚴忌 and Mei Sheng 枚乘. At that time he wrote his rhapsody Zixu fu 子虛賦. After the death of Prince Xiao of Liang 梁孝王 he returned to Sichuan. On the way he became acquainted with Zhuo Wenjun 卓文君, the daughter of a merchant, that was very fond of music. The families of both were not very rich, and so both lived as wine traders in Linqiong 臨邛.
When Emperor Wu 漢武帝 (r. 141-87 BCE) succeeded to the throne, he invited Sima Xiangru to the court because the rhapsody Zixu fu had impressed the young emperor. Sima Xiangru wrote the rhapsody Shanglin fu 上林賦 that Emperor Wu liked very much. He made Sima Xiangru gentleman attendant (lang 郎), later Leader of the court gentlemen (zhonglangjiang 中郎將). He was also sent on a mission to southwestern China to make arrangements with the native tribes of that region. On that occasion Sima Xiangru wrote the texts Yu Ba-Shu xi 喻巴蜀檄 and Nan Shu fu lao 難蜀父老.
After his return to the capital he was accused of having accepting bribes during his journey, and retired. Yet after less than a year he was again appointed court gentleman and then Director of the Xiaowen Garden 孝文園令, but he was already so sick that he could not take over any duties, and died shortly afterwards, probably by diabetes.
Sima Xiangru's literary achievements mainly lie in his rhapsodies. The imperial bibliography Yiwen zhi 藝文志 in the official dynastic history Hanshu 漢書 says that he had written 29 rhapsodies. Of these, only six have survived in full (Zixu fu 子虛賦, Shanglin fu 上林賦, Daren fu 大人賦, Changmen fu 長門賦, Meiren fu 美人賦, Ai Qin Ershi fu 哀秦二世賦), and of three others, the titles are known (Li fu 梨賦, Yuju fu 魚葅賦, Zishan fu 梓山賦).
His most representative works are the Zixu fu and the Shanglin fu that are both quoted in the Liang-period 梁 (502-557) anthology Wenxuan 文選. It is probable that the two texts were in fact only one, with the title of Tianzi youlie fu 天子游獵賦.
The Zixu fu is compiled as a kind of dialoge between Master Zixu 子虛先生 of the ancient state of Chu 楚 (modern Hubei) and Master Wuyou 烏有先生 of the state of Qi 齊 (modern Shandong). Master Zixu praised the majesty of the land of Chu, and the rich entertainments that the king of Chu is able to enjoy, particularly hunts in the vast wilderness. He is criticized by Master Wuyou who says that the richness and beauty of the land says nothing about the moral and virtue of the king of Chu. Quite inconsistent is Master Wuyou's own praise of the vastness and richness of the land of Qi.
The part Shanglin xu is a critique of the two masters' standpoints. None of them does lay stress on the proper behaviour of a ruler and his ministers, the etiquette among the regional rulers (zhuhou 諸侯), but only praises the extravagance of music and plays and the grandeur of the royal hunting parks. With its concrete description how the parks looked like and how the hunting activities were implemented, the rhapsody is an indirect critique of the imperial hunts in the Shanglin Park 上林苑, with the morale that a ruler does not only have to care for his own pleasure, but that he has to obey propriety and moral principles of government.
Sima Xiangru even goes so far to directly address the emperor, to show that he had to give up "this prodigious luxury" (da shechi 大奢侈) and to abstain from wine and hunts (jie jiu ba lie 解酒罷獵). The rhapsodies of Sima Xiangru are so a comibination of describing the majesty of the Han dynasty, and a criticism of the extravagancy of the court life. This criticism has been rejected by the late Former Han period writer Yang Xiong 揚雄 who saw Sima Xiangru's admonishions as not suffient enough because they constitute only one per cent of the whole text (quan bai er feng yi 勸百而諷一 "hundred encouragings against one criticism").
The language of the two rhapsodies itself is very extraordinary. It is majestic and beautiful, rich in the use of words, and with a vivid attractiveness. Yet on the other hand Sima Xiangru uses a lot of uncommon words and characters that make it very difficult to read the text. Liu Xie 劉勰 says in his literary critique Wenxin diaolong 文心雕龍 that "only masters can analyse the words, and only literati perceive its meaning" (fei shichuan bu neng xi qi ci, fei boxue bu neng zong qi li 談者非師傳不能析其辭，非博學不能綜其理).
The other surviving rhapsodies of Sima Xiangru belong to the elegiac type of rhapsodies (saoti 騷體) and are written in a very sad mood. The Changmen fu, for instance, describes how Empress Chen 陳皇后 lost the favour of Emperor Wu, her feelings and bitter complaints. In many parts of his rhapsodies, especiall in the Daren fu, Sima Xiangru was influenced by the early elegiac rhapsodies in the collection Chuci 楚辭, in which the narrator is able to leave the world and to fly on clouds like an immortal. He even mentions methods thought to render immortality, like the consumption of certain herbs or mushrooms, or abstinence from eating grains.
Sima Xiangru's rhapsodies occupy an important position in the history of this literary genre. He was one of the early Han writers who created the mature form of the "greater rhapsody" (dafu 大賦) with its descriptions of capitals, palaces, gardens, imperial hunts and inspection tours. Yang Xiong later said that if the Confucians had selected the rhapsody as their genre, Jia Yi 賈誼 (writing around the same time as Sima Xiangru) would have been the one climbing the stairs of the Great Hall, and Sima Xiangru the one who entered the temple. Ge Hong 葛洪 (in the Xijing zaji 西京雜記) quotes Sima Xiangru to have said that writing rhapsodies was done by collecting material to create the text, and by spreading out of brocades and embroideries as the fabric (he zuanzu yi cheng wen, lie jinxiu er wei zhi 合綦組以成文，列錦繡而為質). The text "embraced the universe and gave an overview of mankind" (bao kuo yuzhou, zong lan renwu 苞括宇宙，總覽人物).
There are also a few writings of other genres written by Sima Xiangru, like his memorials Shang shu jian lie 上書諫獵 and Fengshan wen 封禪文 (see fengshan offerings), as well as his poems Qin ge 琴歌 and Jiaosi shi 郊祀詩.
The imperial bibliography Jingji zhi 經籍志 in the history Suishu 隋書 lists the collected works Sima Xiangru ji 司馬相如集, with a size of 1 juan "scroll", but they are lost. The Ming-period 明 (1368-1644) scholar Zhang Pu 張溥 has collected fragments of Sima Xiangru's oeuvre, the Sima wenyuan ji 司馬文園集, which is included in the collection Han-Wei-Liuchao baisan jia ji 漢魏六朝百三家集.