All the talk beforehand was of the duel between hot shots Aaron McLean and John Grant, but in the end it was Ryan Williams who claimed the points six minutes from time, with a wonderful free kick from 28 yards out.
It was no more than Aldershot deserved. They carved out the better chances, won most of their tackles and played the most attractive football throughout.
Terry Brown's side also showed more character than their promotion rivals, forcing their way back into the game following Michael Kightly's equaliser and showing the adventure and desire needed to take home the points that have moved them into third.
However, in the opening 10 minutes it didn't look like the Shots would be coming away with anything, as the hosts stamped their authority on the game immediately.
Former Aldershot hero McLean flashed a header over early on and then, with five minutes on the clock, Glenn Poole played a beautiful ball right across the six-yard box but Kightly just couldn't stretch enough to get the touch it needed to open the scoring.
Moments later, the rampaging Dennis Oli burst forward from midfield and smashed a drive inches over from 25 yards out and the signs were looking ominous for the Shots, who were being completely overrun.
However, Ricky Newman — the only change to Saturday's team as he came in for Ben Harding — drove the midfield forward, biting into tackles and demanding more from his team-mates, and slowly but surely the visitors began to settle down.
With 20 minutes gone, the former Crystal Palace midfielder won a tackle 35-yards out before picking out Williams on the left flank with an arrowed pass.
The winger — clearly man-of-the-match — cut back onto his right foot and curled a delicious ball onto the head of Joel Grant in the box, but his effort was brilliantly pushed past the left hand post by the outstretched hand of keeper Ashley Bayes.
On 24 minutes Grant had another chance when a quick free-kick by Newman near the centre circle found Andy Edwards unmarked to the left of the box.
The defender, who had a spell on loan at Grays last year, headed it back across goal into the packed area, where Grant was lurking at the back post. As the ball came to him, he set himself and hit a powerful half volley from eight yards out, only to be denied once more by former Woking star Bayes.
By this stage Aldershot were almost camped in the Grays half, but Nikki Bull was still called upon to make two smart stops before the break, firstly from Kightly and then Poole.
It would have been harsh on Brown's men if they had trailed at the break after such a dominant spell, but while they may have settled for a point beforehand it was clear the game was there to be won.
With eight minutes of the second period gone, Joel Grant was put clear on the right flank by Louie Soares, before delivering a hanging cross right to his strike partner John at the far post, who looked destined to score.
Bayes though, had other ideas and instinctively threw himself at Grant's header, blocking it well before beating it away, leaving the Shots wondering what on earth they had to do to score.
However, on the hour mark they finally had something to celebrate after Dave Winfield scored in the most controversial of circumstances.
A Ryan Williams corner from the left was tossed into the middle of danger zone, where Phil Anderson challenged Djoumin Sangare for the header, and the ball popped up to the feet of Winfield six yards out.
The young centre back swivelled and turned the ball towards goal, before Bayes leapt on it, right on the line. Every Shots' hand nearby went up, claiming it had crossed the line and, after consulting with his linesman, the referee agreed with them and awarded the goal.
With a sense of injustice suddenly coarsing through their veins, and roared on by an indignant home crowd, Grays came straight back, with the Shots affording them far too much room and an equaliser began to look imminent.
McLean, Sangare and Lee Boylan all went close in a matter of minutes before Kightly finally levelled the scores, breaking in from the right wing before crashing a left footed drive right into the bottom left hand corner to make it 1-1.
It looked to all the world as if Grays would push on for the winner now, but the goal seemed to have the opposite effect on them and Brown's men went back on to the front foot in search of another goal.
After 76 minutes, a Williams free-kick from the edge of the area flew just millimetres wide of the top right hand corner, but despite his anguish, it turned out he was merely setting his sights.
Eight minutes later Sangare pulled down John Grant to the left of the D, 28 yards out and another free-kick was awarded to the Shots.
Williams stepped forward and stunned the home fans with an unstoppable curling effort that gave Bayes no chance as it seared into the top left hand corner. Cue delirium in the away end.
As if conscious of what they might achieve, the Shots players suddenly looked nervous again and when the fourth official indicated there would be five minutes of added time, an anxious wait ensued.
Two minutes into injury time, a corner by Kightly from the left found the head of the onrushing McLean, who sprang high and powered a strong header towards the top left hand corner.
However, Dean Smith was stationed on the line and he headed it over.
With Shots' hearts in mouths, the resulting corner fell to Sangare and his header careered off the left post, before falling invitingly to Boylan five yards out, but the striker's half volley went over and that was that. A massive win for the visitors.
Afterwards, Brown said: “I have mixed feelings really because I was delighted with the first half performance. I spoke to them at the break about taking the game to Grays to win it and we did that, got our goal and then went into defensive mode.
“We dropped at least another 10 yards deeper, and I thought ‘what are you playing at?'. The left side did well today, but not so much the right side. They both had poor games.
“I expect more out of Dean Smith and Louie Soares because they are quality players. Had they had the courage and belief to get the ball down and pass it we could have done even better tonight.
“It sounds a bit picky but we have to improve. We've nicked three points — a very important three points — but I want us playing better than that and making the margins larger in future.”
Aldershot travel to Cambridge United tomorrow evening - ko 7.45pm and should welcome back Marcus Gayle. However, Rhys Day and Mark Molesley will miss out, while Darren Barnard may struggle as well.
With thanks to the Aldershot News.