Failing the New York State teachers’ exam really paid off — especially for a Queens man who learned this month he’s getting a $2 million windfall over it.

Roughly 5,200 black and Hispanic ex-Big Apple teachers and once-aspiring educators are expected to collect more than $1.8 billion in judgments after the city stopped fighting a nearly three-decade federal discrimination lawsuit that found a certification exam was biased.