Gloucestershire 320 (Higgins 73, Bracey 65, Brathwaite 60) and 14 for 0 trail Hampshire 470 (Alsop 149, Holland 114, Dawson 65, Vince 52) by 136 runs
Hampshire had looked on course for a third successive LV= County Championship victory when the pair came together with 22 overs of the day remaining and their side leading by just 11 runs.
However, Goodman and Shaw soaked up 106 balls between them in a 36-run stand to frustrate the hosts who had ripped through the middle and lower order in a devastating spell after tea.
Goodman, 20, who is still a student at Exeter University and playing only his second first-class match, was unbeaten on 9 having faced 39 deliveries before scoring, with Shaw 23 not out after an hour-and-20-minute stint at the crease.
Gloucestershire, who were made to follow on late on Saturday, started the day on 14 for 0 with Chris Dent and Kraigg Brathwaite surviving the opening 40 minutes from Kyle Abbott and Mohammad Abbas with few alarms.
But it was first-change bowler Brad Wheal who made the breakthrough when he found the edge of Dent's bat and Liam Dawson took a brilliant juggling catch in the slips to dismiss the visiting skipper for 10.
In the very next over Brathwaite undid all of his hard work when he tried to smash Dawson back over his head but instead picked out Abbott at deep mid-on.
Dawson then snared the in-form James Bracey for his first single-figure score of the season when he tried to drive the ball out of the foot marks but could only divert it to Ian Holland at slip to leave Gloucestershire in deep trouble at 50 for 3.
Tom Lace and Ian Cockbain steadied the ship until an hour after lunch when the former Middlesex batter, who'd played well for his 38, was brilliantly caught at slip by Joe Weatherley off Wheal.
But Cockbain, a white-ball specialist, playing his first four-day match for three years, dug in manfully for 36 from 122 balls as Gloucestershire lost just one wicket in the middle session.
Abbot struck immediately after the restart when he dismissed Cockbain and the dangerous Ryan Higgins before Wheal snared George Hankins and Dan Worrall in successive balls.
Mason Crane then trapped Matt Taylor lbw leaving the jubilant hosts pondering a memorable victory, but Shaw and Goodman held out to deny James Vince's side.
"It's been a tough four days," said Ian Harvey, Gloucestershire's head coach. "They played exceptionally well and put us under pressure from day one, winning the toss and batting first then putting on a mammoth total. Our boys had to work extremely hard for the last two-and-a-half days with the bat and we did that.
"We had to dig deep today and nearly avoided the follow-on yesterday against a very good attack. Credit to them they spent a lot of time in the field and they went right at us until the end but our dressing room had to work their socks off and they did that today. Everyone had to play their part and that partnership and the end between Josh and Dom was fantastic."
Hampshire captain James Vince added: "I am immensely proud of the guys. It was a massive effort to follow on. That pitch gave glimpses of it deteriorating and then glimpses of being flat.
They guys gave it everything. We dominated the game and deserved to get over the line given the way we performed, but credit to their last two there they fought well and managed to get the draw. But I can't fault the effort, but the way we have started the season has been fantastic."