We investigate the fundamental factors controlling polymorphism in 5-fluorouracil by performing molecular dynamics simulations of solutions of the compound in water, nitromethane, and wet nitromethane. Analysis of the effect of solvent on the initial aggregation of 5-fluorouracil molecules shows that the strong binding of water to the 5-fluorouracil molecule hinders the formation of the doubly hydrogen-bonded dimer and, by default, promotes close hydrophobic F...F interactions that are a feature of the unusual (Z' = 4) structure of form I. In contrast, doubly hydrogen-bonded dimers are observed to form readily in solution in dry nitromethane, consistent with the crystallization of the doubly hydrogen-bonded ribbon structure of form II from this solvent. When nitromethane is doped with water, the water forms hydrogen bonds to the solute, interfering with the formation of the doubly hydrogen-bonded dimers, which is consistent with the crystallization of form I from this hygroscopic solvent when it is not dried. Overall, the molecular dynamics simulations provide an atomistic picture of how solvent-solute interactions can significantly affect the initial association of 5-fluorouracil molecules to the extent that they determine the polymorphic outcome of the crystallization.