The interaction of crystallographic twin boundaries with an external magnetic field as a mechanism for shape deformation is analyzed theoretically and applied to the alloy Ni2MnGa. A defect, modeled as a Gaussian strain distribution interacting elastically with the twin boundary, is localized in one of the two variants bordering the twin boundary. Micromagnetic equations are used to determine the magnetization angles throughout the variants as well as the equilibrium positions of the twin boundary. These values of the magnetization angle are now incorporated into equations governing the time dependence of the twin boundary motion. The minimum velocity to maintain twin boundary motion in the presence of defects is determined as a function of defect strength and applied field. The results show, among others, a resistance to twin boundary motion due to lattice discreteness and a large but temporary reduction in twin boundary velocity during the interaction between the localized pulse and the defect. Finally, a distribution of stress-related defects is postulated and the relative elongation of the material as a function of the applied magnetic field is obtained. Further, experimental results on the temperature dependence of the magnetic anisotropy and magnetization, as well as the effects of random thermal fluctuations, are included in our micromagnetic equations. The upper limit to the magnetic field driving force then becomes a function of the temperature dependence of the anisotropy. We show that the random thermal energy input is critical to overcoming stress-related obstacles to twin boundary motion.