The veteran Senegal midfielder found the net for the first time in English football since he scored for Fulham against Blackburn – exactly six years ago to the day.
The Hammers wasted numerous chances to add to Diop’s early header, but Barnsley could not take advantage and a sell-out Upton Park was able to celebrate victory after two successive defeats had dented their promotion bid.
The win moved Sam Allardyce’s side level on points with leaders Southampton, who play at south-coast rivals Portsmouth on Sunday.
West Ham went into the clash riddled with injuries and suspensions, so boss Allardyce could have been forgiven for thinking the world was against him when Abdoulaye Faye pulled out of the warm-up.
That meant left-back George McCartney filled in at centre-half with 17-year-old Daniel Potts, son of former Hammers skipper Steve, fast-tracked into his debut.
However, the home side shrugged off that early blow and took the lead after just six minutes, Mark Noble swinging in a corner and Diop launching his considerable frame above the Tykes defence to crash his header past Luke Steele.
Potts only signed a professional contract the day before the game, and his first appearance came just two years after he was given the all-clear after a battle with leukaemia.
The youngster was showing no signs of letting the occasion get to him and twice almost set up another goal with fine left-footed crosses which Carlton Cole and James Tomkins failed to make the most of.
The Hammers shouted for a penalty after 18 minutes when Fredi Piquionne’s run into the box was halted by Jay McEveley, but referee Scott Mathieson was not impressed.
Cole should have doubled the lead on the half-hour when, having run on to Noble’s through-ball, he appeared to have done the hard work in holding off two defenders and side-stepping Steele only to screw his shot wide.
And just before the break a last-ditch challenge from Rob Edwards prevented Piquionne from finding the net.
Allardyce has bemoaned his side’s lapses of concentration for letting in crucial goals this season and they dozed off again at the start of the second half, moments after a stray cat had interrupted proceedings, but Rob Green made a fine save from Edwards’ header.
With seven minutes left Allardyce felt Freddie Sears should have had a penalty as the youngster tumbled in the area, and in his frustration aimed a kick at some plastic bottles before being sent to the stands by referee Mathieson.
But Allardyce took his seat among the fans and watched his side see out a nervy ending to get back to winning ways.