Arsenal's nine-match winless streak looked set to reach 10 after a lifeless first half, in which the Gunners conceded. They were booed off at the break.
For almost an hour they were characteristically woeful and listless, then out of nowhere Gabriel Martinelli scored his first league goal in his first league start, clinically finishing a cross from the left by Sead Kolasinac in the 60th minute.
Arsenal suddenly came to life. Pierre-Emerick Aubameyang collected the ball outside the box and fed it out right to Nicolas Pepe, who curled the ball past goalkeeper David Martin to put Arsenal in front.
Moments later, Arsenal carved West Ham open again, Mesut Ozil fed Pepe on the right, and his cross found Aubameyang, who was just onside to fire in a crisp volley.
Three goals in a quickfire nine minutes from the Gunners prompted West Ham fans to depart the Olympic Stadium in droves.
The win lifted Arsenal to ninth in the standings and ended an alarming run of form which cost Unai Emery his job. Freddie Ljungberg was still coy on whether he wants to take the reins full-time.
Either way, he will start planning for a Europa League group game at Standard Liege on Thursday, while his West Ham counterpart Manuel Pellegrini will still be hoping to be in a job by then.
West Ham has gone winless in five home matches.