Invariant floral forms are important for reproductive success and robust to natural perturbations. Petal number, for example, is invariant in Arabidopsis thaliana flowers. However, petal number varies in the closely related species Cardamine hirsuta, and the genetic basis for this difference between species is unknown. Here we show that divergence in the pleiotropic floral regulator APETALA1 (AP1) can account for the species-specific difference in petal number robustness. This large effect of AP1 is explained by epistatic interactions: A. thaliana AP1 confers robustness by masking the phenotypic expression of quantitative trait loci controlling petal number in C. hirsuta. We show that C. hirsuta AP1 fails to complement this function of A. thaliana AP1, conferring variable petal number, and that upstream regulatory regions of AP1 contribute to this divergence. Moreover, variable petal number is maintained in C. hirsuta despite sufficient standing genetic variation in natural accessions to produce plants with four-petalled flowers.