The flame-haired midfielder lashed a stunning volley into the bottom corner from 20 yards as the Grecians got the win they needed to stay up and sent Gillingham tumbling into League Two instead.
Exeter made the worst possible start and found themselves behind after two minutes. Matt Taylor completely left Richard Duffy's pass and Gary Roberts was quickly on to it. He twisted and turned on the edge of the penalty box before firing a low shot that Paul Jones got a hand to but could not keep out.
The Grecians went on to dominate the rest of the first half, forcing a number of corners, and it was from one of those that Taylor made amends with the equaliser. The Exeter captain met Harley's delivery with a powerful header that flew past Alex Smithies.
Bertie Cozic and Liam Sercombe were narrowly off target with long shots for the Grecians as they finished the first half strongly, while Huddersfield showed little in attack.
They improved after the break and Roberts and Jordan Rhodes were both denied by excellent saves from Paul Jones but, as the tension around St James Park grew, Harley came up trumps for Exeter with a glorious strike to send the crowd wild.