Huddersfield asked all of the questions in the first half, with Sean Scannell and Callum Woods both going close for the hosts.
However, Mark Robins had to wait until shortly before the break to see his side take the lead as Robert Olejnik pushed Oliver Norwood's strike straight to Neil Danns, who easily slotted the ball home.
Peterborough carried a bigger threat early in the second half and Nathaniel Mendez-Laing created the equaliser with a brilliant run before setting up Lee Tomlin, who finished confidently for his 11th goal of the season.
The introduction of Jermaine Beckford seemed to give Huddersfield confidence and he combined brilliantly with Scannell shortly after his arrival, but the latter failed to hit the target from the edge of the box.
Huddersfield regained the lead in the 67th minute when Norwood's testing delivery evaded the Peterborough defence before finding Murray Wallace, who headed past Olejnik.
However, Peterborough snatched a crucial point when Gayle found space to head home from a corner in the 85th minute.