We show a sharp conformally invariant gap theorem for Yang--Mills connections in dimension 4 by exploiting an associated Yamabe type problem. This is joint work with Matthew Gursky (University of Notre Dame) and Jeffrey Streets (University of California, Irvine).