We show that a criterion for confinement, based on the BRST invariance, holds in four dimensions, by solving a non-Abelian gauge theory with a set of exact solutions. The confinement condition we consider was obtained by Kugo and Ojima some decades ago. The current understanding of gauge theories permits us to apply the techniques straightforwardly for checking the validity of this criterion. In this way, we are able to show that the non-Abelian gauge theory is confining and that confinement is rooted in the BRST invariance and asymptotic freedom.