We prove a strong compactness criterion in Sobolev spaces: given a sequence $(u_n)$ in $W_{\textrm{loc}}^{1,p}(\Rd)$, converging in $L_{\textrm{loc}}^{p}$ to a map $u\in W_{\textrm{loc}}^{1,p}(\Rd)$ and such that $|\n u_n | \le f$ almost everywhere, for some $f\in L_{\textrm{loc}}^{p}(\Rd)$, we provide a necessary and sufficient condition under which $(u_n)$ converges strongly to $u$ in $W_{\textrm{loc}}^{1,p}(\Rd)$. In addition we prove a pointwise version of the criterion, according to which, given $(u_n)$ and $u$ as above, but with no boundedness assumptions on the sequence of gradients, we have $\n u_n \to \n u$ pointwise almost everywhere.