The Mexico international, whose diving header had made it 3-3 with six minutes left, nodded the ball in again from Felipe Anderson's cross to send the London Stadium crowd into raptures. "Javier played well in past games but he was maybe under pressure to score. Now he's come off the bench and scored two," West Ham manager Manuel Pellegrini told the BBC.
"I hate it when my team play bad. Winning or losing I want to play well. But winning is the important thing. Winning 4-3 and scoring three in the last 10 minutes is good for the team and the fans." Defender Angelo Ogbonna had given the home side hope with a header from Aaron Cresswell's corner after Huddersfield scored three goals in a league match for the first time this season through Karlan Grant's double and a Juninho Bacuna strike.
Earlier, West Ham took the lead in the 15th minute through skipper Mark Noble who drilled his penalty past goalkeeper Jonas Lossl after midfielder Manuel Lanzini was brought down by teenager Aaron Rowe. The visitors responded almost immediately with their first shot on target as an unmarked Bacuna rose well to meet fellow midfielder Aaron Mooy's whipped corner with a powerful header past Lukasz Fabianski.
Huddersfield went 2-1 up late in the first half with a well-worked free kick routine that led to Grant tucking in Chris Lowe's low cross from the left. Grant's second was a powerful effort from distance in the second half. A frustrated Grant explained how Huddersfield squandered the lead to lose their third match in a row.
"It's a tough one to take, 3-1 up away from home... we have to do better from there. Don't concede three when you're 3-1 up, it's that simple," he said. "Everyone's gutted. I scored two but we didn't walk away with three points, that's what hurts most. We have to play for pride at the moment. We're in a tough place. We need to stick together and go again."
Huddersfield have lost 16 of their last 18 league matches to sit bottom of the table with 14 points from 31 games. (Reporting by Shrivathsa Sridhar in Bengaluru, editing by Ed Osmond)