The Hammers bounced back from the double disappointment of seeing Tomas Soucek’s strike ruled out after a lengthy VAR review for offside and falling behind moments later through Willian’s penalty.
Soucek did finally get his first goal for the club in first half stoppage time before Michail Antonio put the hosts in front early in the second half.
Willian’s free-kick brought Chelsea level once more, but the Blues were caught on the counter-attack when Antonio teed up Yarmolenko.
Victory takes David Moyes’s men up to 16th, three points clear of the relegation zone, but Chelsea were left to rue a missed opportunity to cement their place in the top four.
Frank Lampard’s side had won all three previous games since returning from football’s shutdown due to coronavirus and dominated early on with the in-form Christian Pulisic inches away from opening the scoring.
However, the visitors did not learn from the reprieve they received when Soucek bundled the ball home after a goalmouth scramble from a corner.
Antonio was adjudged to be interfering with goalkeeper Kepa Arrizabalaga’s line of vision from an offside position, much to the frustration of the under-pressure Moyes.
Moments later it got even worse for the hosts as Pulisic was chopped down by Issa Diop and Willian confidently dispatched the spot-kick.
West Ham were level before the break, though, as Soucek rose highest at another Jarrod Bowen corner to power home a downward header.
Moyes’s men were then rewarded for a positive start to the second half as Bowen’s low cross was thrashed home by Antonio.
In a feature of many matches since the Premier League’s restart, it took the mid-half water break for the momentum of the game to swing again.
Pulisic remained Chelsea’s most dangerous player and when the American was brought down again just outside the area this time, Willian produced another moment of set-piece magic.
The Brazilian is expected to leave the club when his contract expires later this month after seven years at Stamford Bridge, but he is going out in style after also scoring the winner against Manchester City last week.
Pulisic fired another low shot just wide as the Chelsea pressure in the pursuit of a winner grew in the final 20 minutes.
But it came at the other end against the run of play as Marcos Alonso did not track Yarmolenko’s surge from inside his own half and after he was picked out by Antonio, the Ukrainian cut inside onto his favoured left and fired past Arrizabalaga.
A 10th league defeat of the season leaves Chelsea just two points clear of Manchester United and Wolves in the race for a place in the top four and next season’s Champions League.