In this paper, we establish a sharp Trudinger-Moser type inequality for a class of Schrödinger operators in $\mathbb {R}^2$. We obtain a result related to the compactness of the embedding of a subspace of $W^{1,2}(\mathbb {R}^2)$ into the Orlicz space $L_{\phi }(\mathbb {R}^2)$ determined by $\phi (t)=e^{\beta t^{2}}-1$. Our result is similar to one obtained by Adimurthi and Druet for smooth bounded domains in $\mathbb {R}^2$, which is closely related to a compactness result proved by Lions. Furthermore, similarly to what has been done by Carleson and Chang, we prove the existence of an extremal function for this Trudinger-Moser inequality by performing a blow-up analysis. Trudinger-Moser type inequalities have a wide variety of applications to the study of nonlinear elliptic partial differential equations involving the limiting case of Sobolev inequalities and have received considerable attention in recent years.