|Alexandre Lacazette now has 15 goals since joining Arsenal from Lyon for £46.5m in July|
This was the first match since Wenger announced he would be leaving the club at the end of the season on Friday, after almost 22 years.
Victory was also the perfect warm-up to Thursday's Europa League semi-final first leg against Atletico Madrid.
The Gunners had taken the lead on 51 minutes after Nacho Monreal volleyed in from a corner, but Marko Arnautovic equalised just after the hour mark, rifling a shot past David Ospina.
Aaron Ramsey put the hosts back into the lead in the 82nd minute when his tame cross was not dealt with by Hammers' defender Declan Rice and Joe Hart could only watch as the ball rolled in at his far post.
Alexandre Lacazette made it three as his close-range shot beat Hart at the near post in the 85th minute, before the Frenchman sidefooted in his second four minutes later.
One negative for Wenger will be an injury to Mohamed Elneny, who was taken off the pitch on a stretcher after injuring his foot in a 50-50 challenge with Mark Noble towards the end of the first half.
Victory keeps Arsenal sixth, 11 points behind fourth-placed Tottenham with four games remaining, but while they can still mathematically finish in the top four, their most likely route into the Champions League is by winning the Europa League.
West Ham, who had dominated much of the first half, drop to 15th place, six points from the drop zone.