Deep UV photoluminescence and Hall-effect measurements were employed to characterize Mg-doped AlN grown by metal organic chemical vapor deposition. A strong correlation between the optical and electrical properties was identified and utilized for material and p -type conductivity optimization. An impurity emission peak at 4.7 eV, attributed to the transition of electrons bound to triply charged nitrogen vacancies to neutral magnesium impurities, was observed in highly resistive epilayers. Improved conductivity was obtained by suppressing the intensity of the 4.7 eV emission line. Mg-doped AlN epilayers with improved conductivities predominantly emit the acceptor-bound exciton transition at 5.94 eV. From the Hall-effect measurements performed at elevated temperatures, the activation energy of Mg in AlN was measured to be about 0.5 eV, which is consistent with the value obtained from previous optical measurements. Energy levels of nitrogen vacancies and Mg acceptors in Mg-doped AlN have been constructed.