Josh Koroma's fine late goal, moments after Britt Assombalonga looked to have earned a point for Middlesbrough, sealed a dramatic Championship win for Huddersfield.
Boro captain Assombalonga scored from the spot after being brought down by Naby Sarr to make it 2-2 with seven minutes remaining.
But the Terriers went straight back in front through Koroma's excellent curling effort from inside the area, his fourth of the season.
Boro had taken a 14th-minute lead through Marvin Johnson, before Huddersfield's Carel Eiting and Fraizer Campbell made it 2-1 before half-time.
Visiting duo Assombalonga and Johnson were in the thick of the early action at the John Smith's Stadium, with the former guilty of spurning a fine chance to open the scoring after eight minutes.