We present a novel method for calculating the fundamental gap. To this end, reduced-density-matrix-functional theory is generalized to fractional particle number. For each fixed particle number, M, the total energy is minimized with respect to the natural orbitals and their occupation numbers. This leads to a function, EtotM, whose derivative with respect to the particle number has a discontinuity identical to the gap. In contrast to density functional theory, the energy minimum is generally not a stationary point of the total-energy functional. Numerical results, presented for alkali atoms, the LiH molecule, the periodic one-dimensional LiH chain, and solid Ne, are in excellent agreement with CI calculations and/or experimental data.