Let X be a real nondegenerate projective subvariety such that its set of real points is Zariski dense. We prove that every real quadratic form that is nonnegative on X is a sum of squares of linear forms if and only if X is a variety of minimal degree. This substantially extends Hilbert’s celebrated characterization of equality between nonnegative forms and sums of squares. We obtain a complete list for the cases of equality and also a classification of the lattice polytopes Q for which every nonnegative Laurent polynomial with support contained in 2Q is a sum of squares.