The Hammers showed three changes to the team beaten 2-0 at Cardiff City, with Marko Arnautovic, Pablo Zabaleta and Michail Antonio starting in place of Javier Hernandez, Ryan Fredericks and Robert Snodgrass.
Meanwhile, the injury-hit visitors made five alterations to the side who lost 2-0 at home to Bournemouth, with Tommy Smith, Terence Kongolo, Chris Lowe, Aaron Rowe and Karlan Grant all drafted in.
Seven minutes in the hosts struck the woodwork, with Antonio flicking the top of the crossbar after he had leapt highest to meet a deflected Declan Rice cross.
Seven minutes later the hosts were awarded a penalty when Rowe clumsily knocked over Manuel Lanzini in the area and Mark Noble sent the resulting spot-kick down the middle of the goal, with Jonas Lossl diving away to his left.
However, the lead lasted a mere two minutes before an unmarked Juninho Bacuna met an Aaaron Mooy corner from the right to power home a header from ten yards out.
And the Terriers were 2-1 in front on the half-hour mark as Lowe fizzed in a cross from the left and Grant was given time and space to sidefoot home into the far corner of the net.
Hammers boss Manuel Pellegrini responded to his side's problems by introducing Hernandez for Antonio at the half-time interval.
However, it was Town who almost scored the fourth goal of the game as Bacuna forced Lukasz Fabianski into a fine save with a 25-yard strike.
Samir Nasri was brought on to replace Noble as the hosts tried again to change the flow of the game, with Arnautovic shooting tamely straight at Lossl after fine work from Felipe Anderson.
And the home side were punished further with a little over 25 minutes to play as Grant scored a wonderful solo goal, spinning away from two defenders before curling a superb 20-yard shot past the dive of the stranded Fabianski.
Fifteen minutes from time the Irons pulled a goal back as Angelo Ogbonna headed home from an Aaron Cresswell corner swung over from the left.
And the hosts were back on terms six minutes from time as Nasri swung in a deep cross form the right and an unmarked Hernandez swooped to head home past the helpless Lossl.
Still there was time left for Jason Puncheon to miss a glorious chance for Town and for the home side to spring forward and clinch an amazing comeback win, as Hernandez nipped in to flick a header over Lossl from an Anderson ball in from the left.