Predicting the conditions in which a compound adopts a metastable structure when it crystallizes out of solution is an unsolved and fundamental problem in materials synthesis, and one which, if understood and harnessed, could enable the rational design of synthesis pathways toward or away from metastable structures. Crystallization of metastable phases is particularly accessible via low-temperature solution-based routes, such as chimie douce and hydrothermal synthesis, but although the chemistry of the solution plays a crucial role in governing which polymorph forms, how it does so is poorly understood. Here, we demonstrate an ab initio technique to quantify thermodynamic parameters of surfaces and bulks in equilibrium with an aqueous environment, enabling the calculation of nucleation barriers of competing polymorphs as a function of solution chemistry, thereby predicting the solution conditions governing polymorph selection. We apply this approach to resolve the long-standing “calcite–aragonite problem”––the observation that calcium carbonate precipitates as the metastable aragonite polymorph in marine environments, rather than the stable phase calcite––which is of tremendous relevance to biomineralization, carbon sequestration, paleogeochemistry, and the vulnerability of marine life to ocean acidification. We identify a direct relationship between the calcite surface energy and solution Mg–Ca ion concentrations, showing that the calcite nucleation barrier surpasses that of metastable aragonite in solutions with Mg:Ca ratios consistent with modern seawater, allowing aragonite to dominate the kinetics of nucleation. Our ability to quantify how solution parameters distinguish between polymorphs marks an important step toward the ab initio prediction of materials synthesis pathways in solution.