Yields of prompt and non-prompt J/ψ, as well as Υ (1S) mesons, are measured by the CMS experiment via their μ+μ− decays in PbPb and pp collisions at √sNN = 2.76 TeV for quarkonium rapidity |y| < 2.4. Differential cross sections and nuclear modification factors are reported as functions of y and transverse momentum pT, as well as collision centrality. For prompt J/ψ with relatively high pT (6.5 < pT < 30 GeV/c), a strong, centrality-dependent suppression is observed in PbPb collisions, compared to the yield in pp collisions scaled by the number of inelastic nucleon-nucleon collisions. In the same kinematic range, a suppression of non-prompt J/ψ, which is sensitive to the in-medium b-quark energy loss, is measured for the first time. Also the low-pT Υ (1S) mesons are suppressed in PbPb collisions.