We report on the evolution of the magnetic structure of BiFeO3 thin films grown on SrTiO3 substrates as a function of Sm doping. We determined the magnetic structure using neutron diffraction. We found that as Sm increases, the magnetic structure evolves from a cycloid to a G-type antiferromagnet at the morphotropic phase boundary, where there is a large piezoelectric response due to an electric-field induced structural transition. The occurrence of the magnetic structural transition at the morphotropic phase boundary offers another route towards room temperature multiferroic devices.