West Ham moved level with Southampton at the top of the Championship thanks to a rare goal from Papa Bouba Diop.
The sixth-minute winner came when Mark Noble's corner was headed past Luke Steele in emphatic fashion by Diop.
The Hammers should have extended their lead but Carlton Cole and Frederic Piquionne squandered good chances.
Barnsley almost equalised after a stray cat had interrupted proceedings, but Rob Green made a fine save from Rob Edwards's header in the second half.
West Ham went into the clash riddled with injuries and suspensions with 17-year-old Daniel Potts, son of former Hammers skipper Steve, fast-tracked into his debut.
Potts only signed a professional contract the day before the game, and his first appearance came two years after he was given the all-clear after a battle with leukaemia.
And the Hammers enjoyed the perfect start in front of a sell-out crowd when veteran Senegal midfielder Diop found the net for the first time in English football since he scored for Fulham against Blackburn - exactly six years ago.
Barnsley fought hard for an equaliser but with seven minutes left West Ham manager Sam Allardyce felt Freddie Sears should have been awarded a penalty after the youngster went down in the box, and in his frustration aimed a kick at some plastic bottles before being sent to the stands by referee Scott Mathieson.
Allardyce took his seat among the fans and watched his side see out a nervy ending to get back to winning ways.
West Ham manager Sam Allardyce:
"It was a great debut from [Daniel] Potts both in defence and attack. It was a fantastic result under the circumstances, I'm not sure anyone's squad could cope with being as stretched as ours is in this league."
Barnsley manager Keith Hill:
"We were foraging for a point, but I won't go to direct, percentage football. It's killing English football and I won't resort to it."
Sorry, we were unable to load match stats, please try again.