Microbial contamination is an obstacle to widespread production of advanced biofuels and chemicals. Current practices such as process sterilization or antibiotic dosage carry excess costs or encourage the development of antibiotic resistance. We engineeredEscherichia colito assimilate melamine, a xenobiotic compound containing nitrogen. After adaptive laboratory evolution to improve pathway efficiency, the engineered strain rapidly outcompeted a control strain when melamine was supplied as the nitrogen source. We additionally engineered the yeastsSaccharomyces cerevisiaeandYarrowia lipolyticato assimilate nitrogen from cyanamide and phosphorus from potassium phosphite, and they outcompeted contaminating strains in several low-cost feedstocks. Supplying essential growth nutrients through xenobiotic or ecologically rare chemicals provides microbial competitive advantage with minimal external risks, given that engineered biocatalysts only have improved fitness within the customized fermentation environment.