We have investigated, using ab initio total energy density-functional calculations, the electronic, structural, and magnetic properties of Mn doped InP nanowires. The nanowires have been constructed along the ͓111͔ direction and the dangling bonds on the surface have been saturated by hydrogen atoms. We found that the most energetically favorable position for the Mn atom is near the surface. When the Mn atoms are in "bulklike" positions, the magnetic Mn-Mn coupling in the nanowire is ferromagnetic. In these cases, our results are consistent with a host-p-Mn-d coupling mechanism. On the other hand, if at least one of the Mn atoms is located near the surface, the coupling is antiferromagnetic.