The 27-year-old Sakho, who had replaced Javier Hernandez with just 12 minutes left, scored from close range after being set-up by fellow substitute Arthur Masuaku who had darted down the left flank to create the opportunity.
Just moments earlier, West Ham had come close to breaking the deadlock when Andy Carroll hit the woodwork, again from a pass by French left-back Masuaku who had replaced ex-Swansea star Andre Ayew.
The defeat was a first away from home for Swansea who looked set to hang on for a point in a poor game.
Both sides had chances in the first half with Michail Antonio seeing an effort saved by Swansea goalkeeper Lukas Fabianski after just three minutes.
On the half-hour mark, the Welsh side were foiled when Wilfried Bony was thwarted by Joe Hart.
West Ham moved up to 15th place in the table while Swansea are third from bottom and in the relegation zone.
Download our app and read this and other great stories on the move. Available for Android and iOS.