Earlier, Marcus Trescothick, Ian Blackwell and Peter Trego scored centuries to lift Somerset to 469.
Justin Langer then skied a catch to Jamie Dalrymple at mid-wicket, before Trego took centre stage.
Somerset scored 185-6 after losing the toss, with Trego hitting seven fours and three sixes in his 50-ball innings.
Somerset's total of 176-7 was built on a stand of 79 between Peter Trego (47) and Ian Blackwell (43).
He shared a stand of 99 with Peter Trego (51) as Yorkshire toiled.
Only Shahzaib Hasan (57) batted with purpose as Adil Rashid (2-21) and Peter Trego (2-38) impressed with the ball.
Peter Trego (33) helped him add 81 in 12 overs before giving a return catch to Danish Kaneria with the score on 113.
Wagh pulled Peter Trego for six but in the same over chipped to square-leg, where Alfonso Thomas took an excellent catch.
Afzaal took 32 off one over from Andy Caddick, with four sixes and two fours, before he was caught off Peter Trego.
BBC: SPORT | Cricket | Counties | Afzaal aggression sinks Somerset
Peter Trego had Smith caught at point before Alfonso Thomas had Gareth Batty caught behind as the Somerset attack shared the wickets around.
Somerset were 219-6 when Craig Kieswetter succumbed to Rashid (3-116), but then Blackwell and Trego put them in charge with a terrific partnership.
Peter Trego followed in the next over, caught by Batty at mid-off, before play came to an end with Langer tantalisingly close to making history.
The former Leicestershire left-hander finally departed for 101 in the 47th over when he holed out to Mark Lathwell at long-off from Peter Trego's bowling.
It rose to eight at one point and Somerset sensed a chance when, with 33 still needed, Goodwin was trapped lbw by a slower ball from Peter Trego.
The pair conceded 85 from six overs with the new ball before Trego came on as first change and immediately had Afzaal taken at long-off by Wes Durston.
BBC: SPORT | Cricket | Counties | Afzaal aggression sinks Somerset
But first-innings centurion Blackwell snuffed out any remaining danger with the help of Peter Trego, the pair adding 70 together before Trego hit Rashid to Deon Kruis at mid-off.
Peter Trego made the breakthrough with the wicket of Carberry lbw, then deceived Adams with a slower ball in the 26th over, before taking a one-handed return catch diving forward.
Phillips then had James Franklin caught by Wes Durston at slip and Will Porterfield and Hamish Marsahll both caught by Peter Trego to leave Gloucestershire in dire trouble at 51-5.
Charlie Shreck ended the partnership on 204 and Trescothick followed six runs later to leave Somerset 310-6 but there was no respite for the bowlers as Trego took up the attack.
Peter Trego shared 88 with Blackwell before he was Tahir's third victim but Blackwell, who hit the spinner over long-off for six, added an unbroken eighth-wicket stand of 46 with Alfonso Thomas.
But Brown had his revenge when Trescothick was caught at extra cover, leaving James Hildreth (22) and Trego (20 not out) to do the bulk of the scoring in the closing overs.
BBC: SPORT | Cricket | Counties | Afzaal aggression sinks Somerset
Wicketkeeper Craig Kieswetter helped Trego add 59, scoring his 42 runs off 26 balls, with three fours and two sixes, the latter coming off successive balls from Ryan Watkins in the 17th over.
It ended when Hoggard clean bowled Trego and then trapped Steffan Jones for one, but Blackwell carried on his merry way and reached his century off 137 balls, celebrating by hoisting Rashid for six soon after.
Craig Kieswetter could only contribute 10 before he swiped across the line to Chris Rushworth, but Peter Trego (33 not out) and James Hildreth (31 not out) combined for an unbroken stand of 46 that took Somerset to the close.
Blackwell added impetus with 42 off 39 balls, but Croft removed both him and Peter Trego (41) with the help of catches from Jimmy Maher, the first at slip and the second short mid-wicket, before completing his five-for when Craig Kieswetter holed out at long-on.
BBC: SPORT | Cricket | Counties | Somerset victory seals promotion
应用推荐