Worcestershire went down by five wickets after setting Gloucestershire a 315 target in a minimum of 70 overs on the final day of the Specsavers County Championship clash at New Road.
Ross Whiteley set up an exciting finish by hitting 71 off 88 balls with four sixes and seven fours, equalling his highest score of the campaign.
Then the County attack got to work and reduced Gloucestershire to 141-5 in the first over after tea.
But a counter-attack display of brutal hitting by former Worcestershire batsman Michael Klinger and Jack Taylor tipped the scales back to Gloucestershire.
They figured in an unbroken stand of 179 in 24 overs as the West Country side won with 10.2 overs to spare.
Klinger was unbeaten on 102 from 141 balls with two sixes and 11 fours and Taylor finished 107 not out from 72 deliveries with six sixes and 11 fours.
It was the climax to a superb game of cricket which see-sawed throughout the four days.
Heavy morning rain delayed the start but play was able to get underway at 11.30 with only the loss of eight overs.
Worcestershire resumed on 151-5 in their second innings – a lead of 226 with Whiteley unbeaten on 20 and Ben Cox seven.
The game had been opened up for the possibility of a positive result after Gloucestershire had declared 75 runs behind.
Cox collected the first boundary off the morning as he whipped Liam Norwell off his legs and then Whiteley on drove the same bowler to the ropes.
The left hander then lofted Norwell for a big six over long on and leg glanced David Payne for another boundary.
Norwell had Cox caught behind for 18 after he tried to cut a shorter ball and vice-captain Joe Leach (4) holed out on the deep mid wicket boundary off Craig Miles.
But Whiteley continued to blaze away to telling effect and a cut for four off Norwell took him to a 53 ball 50.
It contained three sixes and five fours.
Barnard (7) was caught at cover off Miles and then in the same over a superb legside catch by keeper Gareth Roderick accounted for Jack Shantry (0).
Whiteley and Charlie Morris added 24 for the final wicket before the former was caught at long off to give Craig Miles (5-54) his fifth wicket.
Gloucestershire began their reply immediately after lunch and Leach struck in his second over as Chris Dent (5) nicked to Tom Kohler-Cadmore at first slip.
Gareth Roderick looked in good touch for Gloucestershire, reeling off a series of powerful straight drives.
But after making 30 he fell to a stunning catch by Alexei Kervezee off the bowling of Barnard.
Roderick lofted the ball onto the off side and Kervezee ran 20 yards back from mid off to hold onto the catch full length at deep extra cover.
The former Dutch international was mobbed by his team-mates after pulling off one of the catches of the season.
Graeme van Buuren had shown his class in making an unbeaten 172 in the first innings and he again looked in good touch in reaching 42.
But then Charlie Morris brought about his downfall as Van Buuren (42) was undone by a ball of extra bounce and nicked through to Cox.
Kervezee was brought into the attack and in the final over before tea he sent back Hamish Marshall (10) with Barnard showing a safe pair of hands at mid on.
Leach returned to the attack after tea and his first over saw off George Hankins (1) who went for a pull and was lbw at 141-5).
Taylor decided attack was the best form of defence and dominated a century stand in 17 overs with Klinger.
He brought up his half century off 38 balls with four sixes and five fours.
After a brief stoppage for bad light, the players returned with Gloucestershire on 285-5 and they went onto complete victory.