Photoelectrochemical cells are widely studied for solar energy conversion. However, they have rarely been used for the synthesis of high added-value organic molecules. Here we describe a strategy to use haematite, an abundant and robust photoanode, for non-directed arene C–H amination. Under illumination, the photogenerated holes in haematite oxidize electron-rich arenes to radical cations, which further react with azoles to give nitrogen heterocycles of medicinal interest. Unusual ortho selectivity was achieved, probably due to a hydrogen-bonding interaction between the substrates and the hexafluoroisopropanol co-solvent. The method exhibits broad scope and is successfully applied for the late-stage functionalization of several pharmaceutical molecules.