Grayson stepped up with three minutes to go, landing a penalty from the halfway line to put Saints 32-31 up in a breathless encounter against the reigning Gallagher Premiership champions.
And despite being beset by injuries throughout the game, the black, green and gold somehow kept going right until the end as they bagged another memorable bonus-point win.
There was a huge roar at full-time as the outcome was confirmed, meaning Saints claimed their fifth successive maximum haul in the Premiership.
It was an incredible showing packed with pride and passion as Saints strengthened their grip on fourth spot.
They had gone into the game on the back of a sensational comeback win at Bath on the previous weekend, but Saints suffered a big early blow against third-placed Quins.
Juarno Augustus was hurt flying into contact, reducing the hosts to 14 men while the South African No.8 was stranded inside his own 22.
But that didn't matter to the hosts as they flew forward with 14 men, piecing together a superb move that allowed Tommy Freeman to score.
Augustus came off as Grayson landed the conversion to make it 7-0.
But the lead didn't last long as Quins showed what they were made of, delivering a fine effort of their own as Andre Esterhuizen cruised in and Marcus Smith converted.
Saints threatened to respond straightaway as Api Ratuniyarawa's superb offload released Alex Mitchell, but he was stopped at the last by Danny Care.
Another injury blow followed as Conor Carey suffered what looked to be a serious injury, requiring treatment for a number of minutes before he was stretchered off.
But Saints came out firing after the stoppage, delivering another sensational move that allowed Lewis Ludlam to score out wide.
Grayson again slotted the conversion with aplomb to give his side their seven-point lead back.
Saints had yet another injury concern soon after as Paul Hill was down for some time after Quins had been awarded a penalty in front of the posts.
But Hill got back up and Smith slotted the kick to cut the gap to four points.
Saints continued to fly forward though and they were hit by some bad luck as a lovely kick was placed into the path of Matt Proctor, but he slipped in the in-goal area and Quins cleared.
Hill was soon going off for a HIA, which he failed, meaning uncontested scrums as Alex Waller came on.
But again Saints' attacking game came to the fore soon after as they showed so much fizz, finally sending George Furbank over.
Grayson missed from an identical conversion position to his first two kicks to leave the gap at nine points.
Furbank soon had to make a try-saving tackle on Esterhuizen, but Quins didn't have to wait much longer for their second score.
Joe Marchant somehow kept the ball in play, allowing Huw Jones to pick up and score.
Smith converted before Saints came agonisingly close to their bonus-point try as Quins stopped them just short.
But Saints were not to be repelled, and they got their bonus-point score before the break with sheer physicality and tempo sending Waller over.
Grayson converted from in front of the posts and the lead was nine points with three minutes of a frantic first half remaining.
There was still time for Saints to lose a fourth player to injury as Alex Coles was helped off, to be replaced by Alex Moon.
Quins came out of the blocks quickly at the start of the second half as Alex Dombrandt went over and Smith converted to cut the gap to just two points.
The away side now really had their tails up and Saints were struggling to get out of their own half.
Quins soon took the lead as Cadan Murley scored in the corner, with Smith kicking the conversion to make it 31-26 in the away side's favour.
Fraser Dingwall became the next Saints casualty as he walked off gingerly, meaning it was now five injuries for the home side.
Saints responded to another setback with some points as Grayson slotted a welcome penalty.
There was a huge flashpoint with 20 minutes to go as Quins replacement prop Santiago Garcia Botta was sin-binned for contact with the head of Furbank.
There were loud boos as referee Matthew Carley refused to show a red, while Furbank trotted off for a HIA, becoming the sixth Saint to leave the game with an injury.
The final stages of the game became a real slugfest, but there was still one final twist.
Saints won a penalty close to halfway and Grayson stepped up to slot it in nerveless fashion.
It was a stunning effort that drew a huge roar from the Gardens crowd.
And after Danny Care was shown a yellow in the final stages, Saints saw the game out to give their supporters another superb win worth celebrating.
Saints: Furbank (Sleightholme 61); Proctor, Dingwall (Francis 53), Hutchinson, Freeman; Grayson, Mitchell (James 66); Iyogun, Haywood (Fish 75), Carey (Hill 10 (Waller 24)); Coles (Moon 39), Ratuniyarawa; Lawes, Ludlam (c), Augustus (Hinkley 6).
Harlequins: Jones; Lynagh, Marchant, Esterhuizen, Murley (David 59); Smith, Care; Kerrod (Garcia Botta 51), Walker, Louw (Collier 70); Symons, Tizard; Lewies (c), Lawday (Wallace 71), Dombrandt.
Referee: Matthew Carley