Freddie Ljungberg has his first win as Arsenal interim manager at the third attempt.
The Gunners fought back from a 1-0 deficit to run out 3-1 winners at the London Stadium.
Ljungberg saw his Arsenal side draw 2-2 at Norwich and then lose at home to Brighton heading into the trip to face the Hammers.
With the Premier League giants on a poor run and only four points above the relegation zone, a positive result had become all too necessary.
However, Arsenal got off to a poor start against a West Ham side with their own problems.
Fight-Back
Manuel Pellegrini's Hammers took the lead through Italian defender Angelo Ogbonna.
He headed in after a corner had been half-cleared and then the ball floated back in.
Arsenal went into the half-time break with plenty to worry about.
But three goals in nine minutes turned any frowns upside down - at least for one night.
Gabriel Martinelli levelled on the hour mark. Six minutes later, summer signing Nicolas Pepe curled in the lead-goal with aplomb.
And Pierre-Emerick Aubameyang stretched that lead on 69 minutes, turning in Pepe's ball in with a cushioned volley.
The result lifts the Gunners up to ninth, while West Ham remain 16th just a point above the relegation zone.