Thin FePt (001) films, grown by molecular-beam epitaxy on Pt(001), exhibit a very large perpendicular magnetic anisotropy (Ku=5×106 J m−3) and a 100% magnetic remanence in perpendicular field. The lattice misfit between FePt and Pt (1.5%) relaxes through the pileup of a/6 〈112〉 partial dislocations along {111} planes, leading to the formation of microtwins. Atomic force microscopy images demonstrate that this process induces a spontaneous rectangular nanostructuration of the sample, while magnetic force microscopy shows that the microtwins act as pinning sites for the magnetic walls. This leads to square magnetic domains and explains the large coercivity associated with the domain wall propagation.