Veteran Robert Croft rolled back the years to bowl Glamorgan to a 26-run victory over Gloucestershire on the final day at Swansea.
The former England off-spinner claimed four wickets in the space of 23 balls after Glamorgan had set their opponents a target of 248 to win from a minimum of 81 overs.
Gloucestershire looked highly unlikely to get close when they slumped to 132-6, despite 47 from Dan Housego that contained five fours and a pair of sixes.
However, the seventh-wicket pair of Jack Taylor (63) and Ian Cockbain (55) got the visitors back on track with a gritty stand of 63.
Yet Croft, who ended with match figures of 8-104, dismissed both in a devastating spell that was completed when Ian Saxelby drove him to midwicket to end the innings at 221.
Glamorgan had earlier declared their second innings on 204-7 from 50 overs to set up an enthralling finish to the contest - and they were rewarded for their bravery with a 20-point haul.
Glamorgan ended day three at Swansea on 167-5 in their second innings, giving them a lead of 210 over Division Two rivals Gloucestershire.
Stewart Walters led the way for the hosts with 56 as the Welsh county put themselves in a strong position heading into the final day of the contest.
The former Surrey batsman hit seven fours in his half-century, sharing in a 73-run stand with Marcus North (42) after Glamorgan had lost both openers cheaply.
Ben Wright reached the close unbeaten on 31 but Jim Allenby just failed to make it through to stumps unscathed, going caught behind to Ian Saxebly for 21.
Gloucestershire had earlier been bowled out for 165 in their first innings, a decent effort considering they had resumed in the morning on 91-7.
Hamish Marshall, batting in unaccustomed position of nine, weighed in with 31 while Saxelby finished up on 21 not out. Robert Croft finished as the pick of the Glamorgan attack with 4-51.
Glamorgan staged a dramatic fightback on the second day of their LV= County Championship Division Two clash against Gloucestershire at Swansea.
The hosts resumed the day in real trouble at 64-6 in their first innings, but Dean Cosker and Huw Waters added 83 runs for the last wicket to lift them to 208 all out.
In reply Gloucestershire struggled and finished on 91-7, still 117 adrift on first innings.
Glamorgan had limped to 125-9 when Cosker and Waters came together and the pair did a fine rearguard job for their side.
Waters had made 39 from 76 balls when he was bowled by part-time off-spinner Rob Nicol (4-53), leaving Cosker stranded one short of his half-century after a 61-ball knock.
Waters (1-10) then picked up the early wicket of Chris Dent for one, but it was Jim Allenby (3-20) and Robert Croft (2-32) who did the bulk of the damage as the visitors' batsmen laboured.
Jack Taylor was Gloucestershire's top scorer with 27, while Ian Cockbain was unbeaten on 20 at stumps.
Gloucestershire dominated a rain-reduced first day of their LV= County Championship Division Two clash with Glamorgan in Swansea.
The Welsh county were reduced to 64-6 in the 27 overs of play that were possible - it was still better than the two teams had managed previously this year, with the first fixture between the pair being completely washed out.
Jack Taylor and David Payne took two wickets each to leave Glamorgan, who had won the toss and elected to bat at St Helens, in real trouble.
Payne dismissed both openers, firstly trapping Gareth Rees lbw and then getting rid of William Bragg in the same way after he had battled 37 deliveries for his nine runs.
Sandwiched in between spinner Taylor struck twice, and although Jim Allenby briefly tried to hit Glamorgan out of trouble, managing a six and two fours to race to 25, his counter-attacking effort was ended by Ian Saxelby.
Skipper Mark Wallace also fell before the umpires took the players off the field for bad light shortly after tea. Play was called off for the day at 5.35pm.