Nature has devised many ways of producing males and females. Here, we report on a previously undescribed mechanism for Lepidoptera that functions without a female-specific gene. The number of alleles or allele heterozygosity in a single Z-linked gene (BaMasc) is the primary sex-determining switch in Bicyclus anynana butterflies. Embryos carrying a single BaMasc allele develop into WZ (or Z0) females, those carrying two distinct alleles develop into ZZ males, while (ZZ) homozygotes initiate female development, have mismatched dosage compensation, and die as embryos. Consequently, selection against homozygotes has favored the evolution of spectacular allelic diversity: 205 different coding sequences of BaMasc were detected in a sample of 246 females. The structural similarity of a hypervariable region (HVR) in BaMasc to the HVR in Apis mellifera csd suggests molecular convergence between deeply diverged insect lineages. Our discovery of this primary switch highlights the fascinating diversity of sex-determining mechanisms and underlying evolutionary drivers.