We have measured the polarizations of J/ψ and ψ(2S) mesons as functions of their transverse momentum pT when they are produced promptly in the rapidity range |y|<0.6 with pT≥5 GeV/c. The analysis is performed using a data sample with an integrated luminosity of about 800 pb−1 collected by the CDF II detector. For both vector mesons, we find that the polarizations become increasingly longitudinal as pT increases from 5 to 30 GeV/c. These results are compared to the predictions of nonrelativistic quantum chromodynamics and other contemporary models. The effective polarizations of J/ψ and ψ(2S) mesons from B-hadron decays are also reported.