Two intermetallic phases, R2Fe17 carbide and R2Fe14C, which are promising candidates for permanent magnets, are formed in the iron-rich R–Fe–C ternary alloy system (R = rare earths). Using x-ray diffraction and thermomagnetometry the phase formation, transformation, and thermodynamic relations between the two structures, prepared by high energy ball milling, are studied quantitatively for R = Sm. The results lead to a free energy diagram for the pseudobinary system of Sm2Fe17 and C. A maximum equilibrium carbon content, xc, has been established for the carbide Sm2Fe17Cx and its temperature dependence determined. Beyond the equilibrium concentration, Sm2Fe17Cx transforms into a mixture of Sm2Fe17Cxc, Sm2Fe14C, and α–Fe. Although not thermodynamically stable, Sm2Fe17Cx can still be formed through nonequilibrium processes by being kinetically favored over the stable phase(s). This feature is important for the production of Sm–Fe–C-based permanent magnets.