Electrochemical reactions powered by renewable electricity are an important means of reducing the carbon footprint of large-scale chemical processes. Here, we investigate the efficient conversion of biomass-derived 5-hydroxymethylfurfural (HMF) to 2,5-furandicarboxylic acid (FDCA), an important building block in the polymer and pharmaceutical industries, using a cheap and abundant nickel-based electrocatalyst. We elucidate the key factors for tuning the chemical selectivity for HMF oxidation over the competing oxygen evolution reaction (OER) at the catalyst surface. We show that the selectivity for HMF oxidation is enhanced by removing trace impurities of iron species as well as adjusting the composition of the alkali hydroxide electrolyte solution. LiOH solution without iron impurities is more favorable for HMF oxidation, whereas CsOH solution with iron species present is more active for the OER and unfavorable for HMF oxidation. Under optimized conditions, HMF oxidation in 1 M LiOH electrolyte solution without iron (pH 14) achieved 98% faradaic efficiency for the production of FDCA. The principles used in this work can be applied to other electrosynthetic reactions, in particular where the OER is the main competing side reaction.