The home side were frustrated by the pair and the rest of the County's middle order, who batted out the day after the team slipped to 52 for three before lunch.
But Gouldstone, in only his second Championship match for the County, showed remarkable patience, judgement and skill to bat 199 balls for a superb 67 not out.
Keogh ended the day with the youngster at the crease, making 71 not out from 137 balls, while there was a crucial innings of 36 from 106 balls from Simon Kerrigan as the County closed the day on 250 for five.
It all added up to a day of massive frustration for the home side, and one of great satisfaction for Northants, even though the result saw Glamorgan leapfrog the County who finished the 10 match Group Three campaign in fourth place.
Glamorgan declared on their overnight score of 462 for four for a first-innings lead of 247 runs, and with Northants two batsmen down, they were firm favourites for victory.
Gareth Berg was still missing having suffered an ankle injury in the warm-up ahead of day two, and Luke Procter then missed he final day as he returned home following a family bereavement.
A club statement on Wednesday morning read: “Luke Procter will miss the final day of the ongoing County Championship fixture against Glamorgan.
“Procter left the squad on Tuesday evening following news of a family bereavement. The thoughts of everyone at Northamptonshire County Cricket Club are with Luke and his family.”
Even though that meant they only needed to take eight wickets, a win for the home side would still have been quite an achievement given the length of time lost to rain over the first two days.
And a Glamorgan success looked even more likely when Michael Neser took three quick wickets to disimiss Ricardo Vasconcelos, Emilio Gay and Charlie Thurston.
But Keogh – whose innings came in two parts after he retired on 50 to attend his late grandmother’s funeral service online – steadied Northants' innings and he and Gouldstone made the game safe, with some substantial help from Kerrigan.
Glamorgan started their chase for eight wickets in a rush, and they grabbed their first with just the second ball of the morning.
Vasconcelos was strangled down the leg side by Neser who had received his Glamorgan cap just minutes earlier.
Thurston edged Neser through the vacant third slip area, but Gay was the next to go in the same fashion as Vasconcelos.
Thurston again had a reprieve when another edge – this time from Timm van der Gugten’s delivery – went through the slip corden once more.
Thurston’s luck finally ran out when he edged a good Neser delivery to Chris Cooke for 29 and what was the Glamorgan wicketkeeper’s third catch of the morning.
With Glamorgan’s seam attack on top, it was perhaps a surprise to see captain Cooke turn to spin.
Andrew Salter, Marnus Labuschagne and even Billy Root didn’t look too dangerous as they all had a twirl.
Then Northants' first session went from bad to worse when Saif Zaib was needlessly run out with the last action before lunch. Keogh hit Salter to Labuschagne at cover and the Australian’s throw was too fast for Zaib and Cooke whipped off the bails.
Neser and Labuschagne settled into the attack after lunch but found Keogh and Gouldstone in obdurate mood.
Keogh went to 50 from 112 balls but then immediately retired with family matters on his mind.
Bowler Simon Kerrigan arrived at the crease and Glamorgan sensed an opportunity, but he and Gouldstone put on a 50 partnership.
Salter thought he had got Kerrigan caught at silly point by Labuschagne in the final session and although he was caught behind by Cooke off Michael Hogan for 36 when the second new ball came, Glamorgan couldn’t do enough to force victory.