The discovery of ferromagnetism in Mn-doped GaAs1 has ignited interest in the development of semiconductor technologies based on electron spin and has led to several proof-of-concept spintronic devices2,3,4. A major hurdle for realistic applications of Ga1-xMnxAs, or other dilute magnetic semiconductors, remains that their ferromagnetic transition temperature is below room temperature. Enhancing ferromagnetism in semiconductors requires us to understand the mechanisms for interaction between magnetic dopants, such as Mn, and identify the circumstances in which ferromagnetic interactions are maximized5. Here we describe an atom-by-atom substitution technique using a scanning tunnelling microscope (STM) and apply it to perform a controlled study at the atomic scale of the interactions between isolated Mn acceptors, which are mediated by holes in GaAs. High-resolution STM measurements are used to visualize the GaAs electronic states that participate in the Mn–Mn interaction and to quantify the interaction strengths as a function of relative position and orientation. Our experimental findings, which can be explained using tight-binding model calculations, reveal a strong dependence of ferromagnetic interaction on crystallographic orientation. This anisotropic interaction can potentially be exploited by growing oriented Ga1-xMnxAs structures to enhance the ferromagnetic transition temperature beyond that achieved in randomly doped samples.