The Hammers' frustration looked set to continue in a goalless first half at London Road but Ricardo Vaz Te headed the opener on 51 minutes and Gary O'Neil added his side's second in the 57th minute.
Middlesbrough missed the chance to leapfrog Brighton into fourth place as they were held 1-1 at Ipswich . Lukas Jutkiewicz put Boro ahead in the 63rd minute but Grant Leadbitter equalised 11 minutes later.
Crisis club Portsmouth clambered off the bottom of the table with their second win in two home games. Chris Maguire and Joel Ward both scored in the first half to down Hull 2-0.
Doncaster fell to the foot of the table after a 1-1 draw at Crystal Palace extended their winless run to six games. Jermaine Easter put Palace ahead on 57 before Chris Brown equalised late on.
Nottingham Forest nudged closer to safety after a goalless draw at Leicester , who are now four places adrift of the play-off places.