The Ghana midfielder was once again preferred as a substitute by manager Slaven Bilic whose side has not won a game since February 4 when they defeated Southampton. The Hammers have lost to Chelsea and drawn twice against West Bromwich Albion and Watford.
They took the lead with Marco Antonio early on 10 minutes before King equalized as the clock hit the half hour mark. The Norwegian got his brace to put the hosts into the lead three minutes after the half time break.
Bilic sent Ayew on in place of Algerian Sofiane Feghouli on 58 minutes as his side chased the game.
The Ghana star got his goal seven minutes before full time as the Hammers looked to have rescued a point on the road.
However, King denied them that joy with his goal on 90 minutes.
The defeat left West Ham in 11th spot on 33 points while Bournemouth moved up to 14th with three points separating them.