Ultrawide bandgap III-nitrides, including AlN and high Al content AlGaN alloys, are of great importance for applications to deep ultraviolet photonics and radio frequency electronics. However, lack of suitable substrates remains a challenge. In this context, we investigate the molecular beam epitaxy of AlN and high Al content AlGaN epilayers on low-cost Si substrates using a nanowire template as an intermediate layer.First, the role of the nanowire template on the quality of AlN is elucidated. By comparing AlN epilayers grown with and without the nanowire template over a wide range of growth conditions, it is found that using the nanowire template can relax the tensile strain in the AlN epilayers, as well as improve the overall crystalline quality. Second, the role of the quality of the AlN epilayer on the quality of the p-AlGaN layer grown on top is further discussed. It is found that the improved quality of AlN, due to the use of the nanowire template, also transfers to the improvement of the p-type doping in the AlGaN epilayers grown on top, which further contributes to a drastic improvement on the electrical performance of AlGaN p-i-n diodes, i.e., a factor of 10 4 reduction on the reverse bias leakage current, as well as a 250× improvement on the light output, comparing the structure with and without using the nanowire template. The study potentially impacts the development of ultrawide bandgap III-nitrides on foreign substrates as well as low-cost ultrawide bandgap III-nitride template technologies for a wide range of electronic and photonic device applications.