Cheikhou Kouyate scored the lone goal just before halftime, sending a swerving drive into the corner of the net from the edge of the penalty box.
The victory was a first for West Ham (10-6-16) in the league since winning at Southampton on Feb. 4.
Swansea (8-4-20), who sit at the top of drop zone, are 0-1-4 since beating Burnley on March 4. They created little in return after West Ham took the lead, with Darren Randolph's save from a Luciano Narsingh drive the closest they came to an equaliser.
The Hammers made the better start to the match and thought they were ahead after 21 minutes when Robert Snodgrass headed Michail Antonio's cross towards the target, but Lukasz Fabianski kept the ball out right on the line - as confirmed by goal-line technology..
West Ham lost Antonio to injury with five minutes of the half to go but their mood soon changed when Kouyate strode forward to the edge the area before firing an unstoppable drilled shot beyond the reach of Fabianski in the 44th minute.