We present a study of the polarization of the $\ensuremath{\Upsilon}(1S)$ and $\ensuremath{\Upsilon}(2S)$ states using a $1.3\text{ }\text{ }{\mathrm{fb}}^{\ensuremath{-}1}$ data sample collected by the D0 experiment in 2002--2006 during run II of the Fermilab Tevatron Collider. We measure the polarization parameter $\ensuremath{\alpha}=({\ensuremath{\sigma}}_{T}\ensuremath{-}2{\ensuremath{\sigma}}_{L})/({\ensuremath{\sigma}}_{T}+2{\ensuremath{\sigma}}_{L})$, where ${\ensuremath{\sigma}}_{T}$ and ${\ensuremath{\sigma}}_{L}$ are the transversely and longitudinally polarized components of the production cross section, as a function of the transverse momentum (${p}_{T}^{\ensuremath{\Upsilon}}$) for the $\ensuremath{\Upsilon}(1S)$ and $\ensuremath{\Upsilon}(2S)$. Significant ${p}_{T}^{\ensuremath{\Upsilon}}$-dependent longitudinal polarization is observed for the $\ensuremath{\Upsilon}(1S)$. A comparison with theoretical models is presented.