Despite heading into the game - which was postponed due to weather on February 11 - unbeaten in 10 matches in the npower Championship, the Hammers had drawn their last five, equalling a club record.
But two goals in the space of six minutes early in the second half put the Hammers in control as they moved to within one point of second-placed Reading with their 11th away win of the season.
They took the lead in the 51st minute when Vaz Te headed home a Matt Taylor delivery and then O'Neil doubled his side's advantage with a brilliant curling effort from 25 yards, his second goal for the club.
Kevin Nolan also hit the bar for the Hammers while Peterborough - who hit the woodwork in the early stages - failed to mount a fightback as they lost for the fifth time in seven matches.
Peterborough went straight on to the offensive from the kick-off and Lee Tomlin fired in a bobbling shot from 18 yards which Hammers keeper Robert Green comfortably collected.
The home side went even closer in the 10th minute. Paul Taylor cut inside from the left and curled an excellent shot against the crossbar, with Lee Frecklington's weak follow-up saved by Green.
West Ham struggled to get going in the opening 15 minutes but produced their first effort at goal moments later when Vaz Te's strike from range, which was heading for the bottom corner, was saved by Posh keeper Paul Jones.
Peterborough continued to pass the ball around neatly and another patient move resulted in Taylor having another pop at goal this time failing to test Green from 25 yards.
West Ham started to get on top and had a good spell of pressure. Taylor lofted a shot over the bar before doing likewise with another effort after jinking his way past a couple of defenders and into the box.
The Hammers then had a huge let-off in the closing stages of the first half. A swift Peterborough counter-attack saw George Boyd take the ball down on his chest and volley towards goal but a brilliant block by James Tomkins prevented him from opening the scoring.
Boss Sam Allardyce would have been looking for the away side to up the ante in the second half and that is exactly what they did as Vaz Te headed Taylor's cross back across goal and inside the far post six minutes after the restart.
Kevin Nolan then flashed a shot just wide and things got even better six minutes later when O'Neil produced a fine curling effort into the corner past Jones.
Green produced a stunning save to deny Frecklington and the Hammers nearly added a third in the 67th minute but Nolan's effort hit the bar.
Any reproduction, publication or redistribution of this material without the written agreement of 365 Media Group is strictly forbidden.