A primordial magnetic field (PMF) present before recombination can leave
specific signatures on the cosmic microwave background (CMB) fluctuations. Of
particular importance is its contribution to the B-mode polarization power
spectrum. Indeed, vortical modes sourced by the PMF can dominate the B-mode
power spectrum on small scales, as they survive damping up to a small fraction
of the Silk length. Therefore, measurements of the B-mode polarization at
high-$\ell$ , such as the one recently performed by the South Pole Telescope
(SPT), have the potential to provide stringent constraints on the PMF. We use
the publicly released SPT B-mode polarization spectrum, along with the
temperature and polarization data from the Planck satellite, to derive
constraints on the magnitude, the spectral index and the energy scale at which
the PMF was generated. We find that, while Planck data constrains the magnetic
amplitude to $B_{1 \, \text{Mpc}} < 3.3$ nG at 95\% confidence level (CL), the
SPT measurement improves the constraint to $B_{1 \, \text{Mpc}} < 1.5$ nG. The
magnetic spectral index, $n_B$, and the time of the generation of the PMF are
unconstrained. For a nearly scale-invariant PMF, predicted by simplest
inflationary magnetogenesis models, the bound from Planck+SPT is $B_{1 \,
\text{Mpc}} < 1.2$ nG at 95% CL. For PMF with $n_B=2$, expected for fields
generated in post-inflationary phase transitions, the 95% CL bound is $B_{1 \,
\text{Mpc}} < 0.002$ nG, corresponding to the magnetic fraction of the
radiation density $\Omega_{B\gamma} < 10^{-3}$ or the effective field $B_{\rm
eff} < 100$ nG. The patches for the Boltzmann code CAMB and the Markov Chain
Monte Carlo engine CosmoMC, incorporating the PMF effects on CMB, are made
publicly available.