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 outright 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.