We perform first-principles density-functional theory calculations to investigate the atomic structures and electronic properties of dopant complexes involving Al, Ga, and N in wurtzite ZnO. We find that both Al and Ga substituted on Zn sites act as single donors and exhibit a strong attractive interaction with a nitrogen acceptor located at the nearest-neighbor oxygen site in the same (0001) plane, forming passive (Al-N) and (Ga-N) complexes. These structures induce fully occupied defect states above the valence-band maximum of bulk ZnO. On introducing a higher concentration of nitrogen, (Al-2N) and (Ga-2N) complexes form. The additional N atom in these complexes prefers to occupy another nearest-neighbor site of the Al or the Ga atom, compared to being further away from it, and acts as an acceptor with ionization energies of 0.17 and 0.14 eV, respectively. These values are lower than the ionization energy of the single N acceptor, which is 0.33 eV. This indicates that (Al,N) and (Ga,N) codoping could increase the percentage of N dopants that are activated by ionization. The interaction between two (Al-N) complexes and the interaction between the (Al-2N) complex and a N atom (on a neighboring oxygen site) are very weak, indicating that the N concentration cannot be significantly increased by Al and N codoping or cluster doping. In contrast, two (Ga-N) complexes prefer to bind together in the same (0001) plane, implying that the passive complexes which create the impurity band could reach high concentration. The formation energy for (Ga-2N) is lower than (Al-2N) in the neutral and the negative charge states under most experimental conditions. Furthermore, the (Ga-2N) complex binds with additional N atoms located at nearest-neighbor O sites and therefore has a tendency to form clusters of (Ga-3N) and (Ga-4N). Under Zn-rich conditions and for an NO source of nitrogen, the cluster (Ga-3N) has a lower formation energy and lower transition levels compared to the (Ga-2N) complex; the (Ga-4N) complex has the lowest formation energy and the lowest $(0/1\ensuremath{-})$ transition energy among the (Ga,N) complexes. Our findings suggest that codoping of (Ga,N) could efficiently enhance the N dopant solubility with the NO source (rather than an ${\text{N}}_{2}$ source for nitrogen) and is likely to yield better $p$-type conductivity than (Al,N) codoping.