We present an accurate first-principles study of magnetism and energetics of single Mn impurities and Mn dimers in Si. Our results, in general agreement with available experiments, show that (i) Mn atoms tend to aggregate, the formation energy of dimers being lower than the sum of the separate constituents, (ii) ferromagnetic coupling is favored between the Mn atoms constituting the dimers in p-type Si, switching to an antiferromagnetic coupling in n-type Si, (iii) Mn atoms show donors (acceptor) properties in p-type (n-type) Si, therefore they tend to compensate doping, while dimers being neutral or acceptors allow for Si to be doped p-type. (C) 2004 American Institute of Physics