We report on the magnetic properties of a heterodimer system, namely HoCo. This is a model system for the smallest intermetallic compound of a lanthanide and a transition metal atom. The dimers are adsorbed on ultrathin MgO(100) films grown on Ag(100). New for 4f elements, we detect inelastic excitations with scanning tunneling spectroscopy and prove their magnetic origin by applying an external magnetic field. In combination with density functional theory and spin Hamiltonian analysis, we determine the magnetic level distribution, as well as sign and magnitude of the exchange interaction between the two atoms. In contrast to typical 4f−3d bulk compounds, we find ferromagnetic coupling in the dimer.