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 ℓ, 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 B1 Mpc < 3.3 nG at the 95% confidence level (C.L.), the SPT measurement improves the constraint to B1 Mpc < 1.5 nG. The magnetic spectral index, nB, and the time of the generation of the PMF are unconstrained. For a nearly scale-invariant PMF, predicted by the simplest inflationary magnetogenesis models, the bound from Planck+SPT is B1 Mpc < 1.2 nG at 95% C.L. For PMF with nB = 2, which is expected for fields generated in post-inflationary phase transitions, the 95% C.L. bound is B1 Mpc < 0.002 nG, corresponding to the magnetic fraction of the radiation density ΩBγ < 10-3 or the effective field Beff < 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.