The Shockley-Queisser (SQ) limit provides a convenient metric for predicting light-to-electricity conversion efficiency of a solar cell based on the band gap of the light-absorbing layer. In reality, few materials approach this radiative limit. We develop a formalism and computational method to predict the maximum photovoltaic efficiency of imperfect crystals from first principles. The trap-limited conversion efficiency includes equilibrium populations of native defects, their carrier-capture coefficients, and the associated recombination rates. When applied to kesterite solar cells, we reveal an intrinsic limit of 20% for Cu2ZnSnSe4, which falls far below the SQ limit of 32%. The effects of atomic substitution and extrinsic doping are studied, leading to pathways for an enhanced efficiency of 31%. This approach can be applied to support targeted-materials selection for future solar-energy technologies.