Using highly ordered porous anodic alumina membrane fabricated with the aid of nanoimprinting as a mask, Ta2O5 nanorod array with uniform diameter, length, and distribution is grown in situ on a Ta substrate by through-mask anodization. The Ta2O5 nanorod array is further transformed into Ta3N5 nanorod array without damaging the nanorod structure by nitridation. Solar-driven photoelectrochemical water splitting with a maximum solar energy conversion efficiency of 0.36% is demonstrated with the Ta3N5 nanorod array after modifying the surface with cobalt-phosphate as a co-catalyst. The Ta2O5 and Ta3N5 nanorod arrays have potential applications in catalysis, photonics, UV photodetection and solar energy conversion.