Magnetic rare-earth orthoferrites RFeO 3 host a variety of functional properties from multiferroicity and strong magnetostriction to spin-reorientation transitions and ultrafast light-driven manipulation of magnetism, which can be exploited in spintronics and next-generation devices. Among these systems, SmFeO 3 is attracting particular interest for its rich phase diagram and the high temperature Fe-spin magnetic transitions, which combines with a very low temperature and as yet unclear Sm-spin ordering. Various experiments suggest that the interaction between the Sm and Fe magnetic moments (further supported by the magnetic anisotropy), is at the origin of the complex cascade of transitions, but a conclusive and clear picture has not yet been reached. In this paper, by means of comprehensive first-principles calculations, we unravel the role of the magnetic Sm ions in the Fe-spin reorientation transition and in the detected anomalies in the lattice vibrational spectrum, which are a signature of a relevant spin-phonon coupling. By including both Smf electrons and noncollinear magnetism, we find frustrated and anisotropic Sm interactions, and a large magnetocrystalline anisotropy mediated by the SOC of the Sm-4 f electrons, which drive the complex magnetic properties and phase diagram of SmFeO 3 .