Jamie Vardy bagged a stunning hat-trick to give Town victory in a remarkable game at the Shay.
Chasetown came to frustrate and appeared to have made a smash and grab raid when they took a 71st minute lead.
But Vardy struck twice in the 83rd and 88th minute to seemingly put the Shaymen on course for the points.
Click play on the console above to see a slideshow of pictures by Bruce Fitzgerald.
Gary Birch levelled in the final minute only for Vardy to pop up again with a stunning strike in the fourth added minute to give Neil Aspin’s side victory.
The last 10 minutes made up for the previous 80 and showed just what a champion side the Shaymen are after they had looked destined to be denied a third win in eight days.
Liam Hogan passed a pre-match fitness test to take his place in an unchanged Town side.
And he was not unduly tested in the opening stages, although he did send one superb cross field ball to Vardy on the left which almost created an opening.
Vardy went on another fine run after five minutes, outstripping the Chasetown defence only to send his low cross straight to the keeper.
The Shaymen continued to press forward and Vardy tested the visitors down the middle soon after but was clearly still finding his range as the through ball for Danny Holland was slightly overhit.
Mark Bower was stunned to be penalised after winning a header against Chasetown’s veteran frontman Gary Birch and happy to see Birch’s powderpuff free kick roll into Jonathan Hedge’s arms.
Town returned to the attack with Danny Lowe heading on a Hedge clearance for Vardy who flashed a first time shot across the face of goal and wide.
Gregory was caught in two minds when he latched onto a Holland flick and the opportunity went while Aaron Hardy’s cross was too close to the keeper - but the Shaymen were starting to dominate.
Vardy pulled the ball back for Gregory who was forced away from goal but turned well only to see his shot blocked.
Holland then picked out Vardy with a stunning crossfield ball with the outside of his foot, but the cross did not match the pass.
Chasetown attacks were rare and when they did threaten in the 20th minute Lowe got in front of Daniel Smith to nod back to Hedge.
A foul on Scott Hogan midway through the first half gave Simon Garner a sight of goal from the resulting free kick which was on target but comfortable for the keeper.
And the Shaymen should have had a penalty when Lowe raced into the area after a Vardy flick and was dragged to the floor but the referee was unmoved by the appeals.
Chasetown forced a couple of corners just before the half hour mark, Hedge turning the first behind and the second landing on the roof of the net.
With the visitors looking to take the sting out of the game at every opportunity, Town struggled to maintain their momentum.
Liam Hogan did well to slide in and prevent Richard Davies from getting in on the left and when Richard Teesdale found Ben Jevons who fired in a shot, Hedge was down smartly to gather.
Sharp passing from Holland and Scott Hogan allowed Tom Baker to win a corner and Chasetown keeper Darren Acton was at full stretch as he cleared.
Town almost got the breakthrough within two minutes of the restart when Lowe sent a diagonal ball towards the right of the area.
Gregory nodded it towards the edge of the six-yard box but James Turner got in front of Vardy to head back to his keeper.
Town had a second decent shout for a spot kick after 50 minutes when Holland was barged over but again he referee waved away the appeals.
But the best chance of the early stages of the second half went Chasetown’s way as Birch got free of Baker and Garner before setting up Jevons whose shot from the right curled just too late to sneak inside the far post.
The home fans were growing increasingly impatient and their mood was not improved by a Vardy shot that flew high over the bar.
Vardy almost redeemed himself with a cross that eventually found Holland, but his shot was blocked.
Town were struggling to find any rhythm but, to their credit, they kept trying to pass the ball although they rarely threatened to unlock a tight Chasetown defence.
Holland picked out Vardy on the left and he pulled it back for Gregory. His touch gave Baker the chance to shoot left footed, but the keeper held onto the ball at the second attempt.
Vardy was in the action again a minute later, keeping the ball in play before crossing deep, but Acton claimed again with Scott Hogan lurking at the far post.
And midway through the half Lowe played a ball over the top for Gregory who controlled well before lifting a shot over the bar.
Having shown little ambition, Chasetown took the lead with 19 minutes remaining when Town failed to deal properly with a free kick, the ball fell to Jevons and he drilled it home.
Garner’s great pass wide for Hardy gave the full back the chance to cross, but all three strikers on the pitch - Lee Ellington had replaced Scott Hogan - ran towards the line and the ball went behind them.
Town finally lifted the gloom with seven minutes remaining from a free kick that was headed in the area by Baker. The ball fell nicely for Vardy who slammed home from close range.
Moments later Gregory got to the by-line, but his cross went deep with the players in the middle all going towards the near post.
And Town should have had a corner when Liam Hogan slammed in a 30-yarder and the keeper tipped over, but the referee gave a goal kick.
They went in front for the first time with two minutes remaining from a Lowe pass over the top that Vardy latched onto.
He got a good first touch and with his second lifted it over the advancing keeper.
That should have been that but, with the board appearing to indicate four added minutes, Birch got on the end of a long ball downfield and levelled it up.
There was still a twist in the tail as Town launched one final attack with the seconds ticking away and Vardy worked a space for himself before lashing home the winner.