The league's tightest defence met its weakest but it was Town who celebrated their first win in eight matches in all competitions to boost their battle for survival.
The home side led inside three minutes through Michael Chopra before Carlton Cole hit a post for the visitors moments later.
A crazy end to the first half saw three goals in the final two minutes plus stoppage time, with Daryl Murphy doubling Town's advantage with a header but Jack Collison halving the deficit within seconds.
Ipswich were then awarded a penalty which Lee Martin converted, and Jay Emmanuel-Thomas added a brace after the break as the Hammers saw their three-game winning run in the league come to an end.
But they stay top after second-placed Southampton were held to a 1-1 draw at home by Cardiff.
Town made a flying start as they took the lead after three minutes. Emmanuel-Thomas held off the challenge of a couple of defenders before teeing up Chopra for his first goal in eight games.
The Hammers came agonisingly close to an equaliser in the sixth minute but Cole's header from George McCartney's delivery hit a post and bounced into the arms of goalkeeper Arran Lee-Barrett.
Moments later, Henri Lansbury, who enjoyed a successful loan spell at Town's East Anglia rivals Norwich, fired a shot wide from 20 yards.
The game was swinging from end to end and Chopra came close to a second in the 35th minute but his close-range header was easy for goalkeeper Robert Green.
West Ham responded and James Tomkins headed a Mark Noble corner over before they fell further behind a minute before the break.
Tommy Smith flicked on a corner and Murphy was on hand to convert from close range - his first goal since November.
But the Hammers produced an immediate response as Collison headed in a Noble free-kick, although amazingly Ipswich went straight up the other end and restored their two-goal cushion.
George McCartney was booked for a foul on Chopra and Martin sent Green the wrong way from the spot.
An excellent save from Green prevented Emmanuel-Thomas from notching a fourth for Town 10 minutes into the second half.
But there was nothing Green could do when Emmanuel-Thomas left fly from 30 yards in the 64th minute to make it 4-1.
Winston Reid and Lansbury were denied by Lee-Barrett as West Ham attempted to get back into the game
Substitute Sam Baldock shot wide when he should have scored and Kevin Nolan was next to be foiled by Lee-Barrett as West Ham continued to fight back.
But Emmanuel-Thomas added a fifth in injury time to cap a miserable night for the Hammers.