AlN epilayers were grown by metal organic chemical vapor deposition on sapphire substrates. X-ray diffraction measurements revealed that the threading dislocation (TD) density, in particular, the edge TD density, decreases considerably with increasing the epilayer thickness. Photoluminescence results showed that the intensity ratio of the band edge emission to the defect related emission increases linearly with increasing the epilayer thickness. Moreover, the dark current of the fabricated AlN metal-semiconductor-metal deep ultraviolet (DUV) photodetectors decreases drastically with the AlN epilayer thickness. The results suggested that one effective way for attaining DUV optoelectronic devices with improved performance is to increase the thickness of the AlN epilayer template, which results in the reduction of the TD density.