The result lifted West Ham to ninth in the table on 27 points from 19 games while Southampton stayed 16th on 15 points, three above the relegation zone after suffering their first home defeat in five matches.
The game sprung to life when Southampton forward Nathan Redmond bundled the ball home with his shoulder in the 50th minute after visiting keeper Lukazs Fabianski parried his initial shot and Oriol Romeu's rebound.
In the absence of first-choice strikers Marko Arnautovic and Javier Hernandez, West Ham lacked cutting edge until Brazilian midfielder Anderson turned the match on its head.
Anderson equalised in the 53rd minute with a stinging first-time shot from 20 metres and completed West Ham's comeback in the 57th when he buried the ball into the top right corner from 13 metres to cap a lightning break by the visitors.
Fabianski had kept out a long-range effort by forward Stuart Armstrong at the other end and marshalled his defence superbly in the closing stages as the Saints threw men forward in search of an equaliser.