The Hammers, who started the game seven points adrift of new leaders Reading, never looked back once midfielder Kevin Nolan tapped the ball home in the sixth minute after Nicky Maynard’s corner had bounced between Barnsley striker Craig Davies’ legs.
Maynard added a fine second with a low finish from the edge of the penalty area after a neat interchange with Nolan in the 23rd minute and Mark Noble cashed in on some more hapless defending 12 minutes later to curl home a third goal from a tight angle.
Five straight draws last month meant Sam Allardyce’s side have seen Reading cruise past them into the top two, but their second league win in eight games was already secured when Ricardo Vaz Te added a fourth goal from close range against his former club early in the second half.
Barnsley have now won only one of their last 10 league matches and were left looking anxiously over their shoulders despite a nine-point cushion between themselves and the bottom three.
Maynard went close to making it five with a spectacular 30-yard shot which crashed back off the crossbar soon after Vaz Te’s effort.
It took the Hammers only six minutes to make the breakthrough as Maynard’s corner from the right somehow found its way to an unmarked Nolan on the goal line and the midfielder prodded the simplest of finishes beyond Barnsley goalkeeper David Button.
Vaz Te, on his first return to Oakwell since his January move to West Ham, saw his overhead kick comfortably held by Button, on loan from Tottenham, before the Hammers extended their advantage in the 23rd minute.
Nolan was this time the provider, cutting the ball back inside on the edge of the penalty area, where Maynard drilled a low shot into the bottom corner.
Barnsley then gave themselves a mountain to climb with some more shocking defending 10 minutes before the break.
Winger David Cotterill played Button into trouble with a short back pass and when the goalkeeper’s clearance rebounded to Noble on the left edge of the area, the Hammers midfielder curled the ball home in some style from a tight angle.
West Ham defender George McCartney’s 20-yard shot was well saved by Button soon after the restart before Vaz Te put the Hammers out of sight with a fourth goal in the 55th minute.
The Portuguese striker latched on to McCartney’s cross from the left six yards from goal and buried the ball beneath Button into the centre of goal.
Barnsley substitute Jim O’Brien went close with a raking drive in the closing stages, but it was another afternoon to forget for Keith Hill’s side.