Based on first-principles spin-density functional calculations, we find that Co-doped ZnO energetically favors a spin-glass-like state due to antiferromagnetic interactions between transition metal atoms, while ferromagnetic ordering is stabilized by electron doping. We find a short range nature in both antiferromagnetic and ferromagnetic interactions, and suggest that a very high doping level of Co ions is required to achieve ferromagnetism, together with a sufficient supply of electron carriers. Our results explain experimental features such as the low reproducibility of ferromagnetic samples and the very low saturation magnetization per Co ion.