Electronic structures and magnetic properties of ZnO:Mn and ZnO:Mn+N systems are investigated using first-principles density functional calculations with generalized gradient approximation. The results provide a fundamental theoretical understanding in the substantial ferromagnetic stability induced by N codoping in the ZnO:Mn system observed experimentally. They demonstrate that the ferromagnetic interaction is due to the hybridization between N 2p and Mn 3d states and is very sensitive to the geometrical configurations of dopants in the ZnO host lattice. The most stable ferromagnetic configuration corresponds to the Mn-N-Mn cluster, energetically strong enough to lead to hole-mediated ferromagnetism at room temperature.