Ian Cockbain played the starring role as Gloucestershire eliminated arch rivals Somerset from the Vitality Blast with a thrilling two-wicket Central Group win at the Bristol County Ground.

The visitors posted 161 for seven after winning the toss under cloudless skies, with captain Lewis Gregory hitting 50 and Babar Azam 42 while Tom Smith finished as the pick of the Gloucestershire bowlers with two for 25.

In reply, Gloucestershire reached 163 for eight off the final ball of the match, with Smith hitting a boundary off Ollie Sale after Cockbain had set up the victory with a brilliant 89 off 57 balls.

The result means a home quarter-final for the hosts, while Somerset were left to reflect on a bitterly disappointing campaign.

They were given a brisk start to their innings by Babar and Steve Davies, who took the score to 53 by the end of the fifth over.

Davies was timing the ball sweetly, but having moved to 31 off 19 balls, he pulled a catch to deep mid-wicket off Josh Shaw.

Gloucestershire then applied their customary mid-innings squeeze, taking pace off the ball with left-arm spinners Smith and Graeme Van Buuren well supported by the wily medium pace of Benny Howell.

Somerset could score only 24 runs between the fifth and 10th overs, the last of which from Howell saw Will Smeed caught at mid-off.

Smith removed Tom Abell to a catch at point in the 11th over and in his next claimed the big wicket of Babar, the Pakistan batsman giving a return catch.

Tom Lammonby reverse swept a catch to deep cover off Van Buuren and Somerset were struggling at 105 for five.

But Gregory supplied much-needed acceleration, hitting the first six of the innings in the 18th over and following up with another maximum over deep square off David Payne.

The Somerset skipper also hit four fours in his 28-ball innings but when he fell to the second ball of the final over, his team could add only two off the last four deliveries.

Sale struck a major blow for the visitors by having Chris Dent caught at deep square leg off the final ball of the second over of Gloucestershire’s reply.

Miles Hammond feathered a catch to wicketkeeper Davies off Josh Davey to make it 20 for two and that became 27 for three when James Bracey mishit a catch to mid-on to give Sale a second wicket.

When Ryan Higgins holed out to deep mid-wicket off 19-year-old left-arm spinner Lewis Goldsworthy, it was 50 for four and much rested on Cockbain, who was looking in dangerously good form.

The first six of the innings was struck by Van Buuren off Goldsworthy in the 12th over, but he then fell to a catch at short third-man off Josh Davey.

Cockbain moved to a classy 35-ball half-century, with seven fours and he and Jack Taylor both hit straight sixes off Goldsworthy as the 15th over went for 19 runs.

Taylor then drove a catch to long-off to give Gregory a wicket but Cockbain cleared the ropes again off Sale and Howell hit Gregory for a straight six to leave 24 required from two overs.

Another Cockbain six off Davey made Gloucestershire favourites, but the batsman then cross-batted a catch to long-on.

The last over, bowled by Sale, began with 13 runs needed but two Howell boundaries followed, before there was another twist when he was caught at long-off.

Three runs were still required when Smith faced the last ball, which he carved over wide long-on for four to loud cheers from Gloucestershire fans in the flats adjoining the ground.