We present a measurement of the helicity of the W boson produced in top quark decays using tt̅ decays in the ℓ+jets and dilepton final states selected from a sample of 5.4 fb-1 of collisions recorded using the D0 detector at the Fermilab Tevatron pp̅ collider. We measure the fractions of longitudinal and right-handed W bosons to be f0=0.669±0.102[±0.078(stat.)±0.065(syst.)] and f+=0.023±0.053[±0.041(stat.)±0.034(syst.)], respectively. This result is consistent at the 98% level with the standard model. A measurement with f0 fixed to the value from the standard model yields f+=0.010±0.037[±0.022(stat.)±0.030(syst.).].