Somerset 175 for 8 (Compton 46, Kieswetter 39) beat Gloucestershire 168 for 6 (Gidman 55, Thomas 3-34) by 7 runs
Acting captain Alfonso Thomas claimed two wickets in the final over as Somerset beat Gloucestershire by seven runs in a NatWest T20 Blast thriller at Taunton.
The home side, who left out skipper Marcus Trescothick following a poor run of T20 form, posted 175 for eight after losing the toss, Nick Compton top-scoring with 46 and opening partner Craig Kieswetter contributing 39.
Benny Howell was the pick of the Gloucestershire bowlers with two wickets for 23 runs from his four overs, while left-arm spinner Tom Smith picked up 2 for 24 from three overs.
In reply, Gloucestershire looked to be cruising on 115 for 1 in the 13th over, but Somerset's bowlers stuck to their task, with Dirk Nannes showing all his experience at the death before Thomas dismissed Howell and Adam Rouse to wrap up victory.
The result keeps Somerset in the hunt for a quarter-final place, while leaving their neighbours with a huge task to qualify.
When Compton failed to score off the first three balls of the game, bowled by David Payne, it seemed Somerset would rue the decision to leave out Trescothick.
But the next delivery disappeared over long-off for six and Compton went on to belie his reputation as a mere accumulator of runs with another maximum and four fours in his 31-ball innings.
Kieswetter was prepared to play a supporting role as the pair put on 69 in 8.1 overs before Howell applied the brakes, having Compton caught at long-on.
Jack Taylor helped Howell reduce the scoring rate and from 90 for 1, Somerset slipped to 141 for 7, despite an entertaining cameo of 24 off 15 balls from South African debutant Colin Ingram. Kieswetter maintained his amazing record of only one score below 37 in his last 17 domestic T20 innings, stretching back to last season.
But it took some last-ditch hitting from Tim Groenewald and Thomas to lift the total beyond 170 and it looked no more than a par score in superb batting conditions.
So it seemed when skipper Michael Klinger, back after a broken toe, and Alex Gidman gave Gloucestershire a flying start, taking the total to 64 by the end of the six overs of Powerplay.
Their stand had reached 89 when Klinger was well caught by Compton, diving forward at deep midwicket off Craig Meschede, having faced 26 balls and hit three fours and a six. Gidman went on to a 37-ball half-century before being pinned lbw by a full ball from Nannes in the 13th over to make it 115 for 2.
Legspinner Max Waller produced a tidy spell of four overs for 27 runs, but there was little support from the seamers as Ian Cockbain and Hamish Marshall took the score to 142 before Marshall holed out to deep square off Thomas for 13.
Cockbain made a bright 29 before spooning a catch to backward point off Groenewald and 28 were needed off the last three overs.
Nannes bowled the penultimate over for only five runs and when Thomas yorked Howell with the fourth ball of the final over eight were still needed. Rouse lofted a catch off the last ball and Somerset celebrated.
"The players are entertainers and it was another game that got my heart ticking at quite a rate," Somerset director of cricket Dave Nosworthy said. "But when you are in a tight situation it's good to be able to toss the ball to Dirk or Alfonso because of their vast experience.
"Marcus's poor T20 form was the reason he was left out. It says a lot about him that he agreed with the decision.''
Gloucestershire director of cricket John Bracewell said: "We lost because of two sloppy overs at the end of Somerset's innings and because we were not good enough at the death. Somerset gave us a lesson in how to bowl the last couple of overs. But again we were very competitive and our T20 cricket has improved a lot this season.''