Surrey 157 for 8 (Dilshan 36, W Gidman 2-23) beat Gloucestershire 152 for 7 (Klinger 45, Ansari 3-27) by five runs

Surrey made sure of a place in the NatWest T20 Blast quarter-finals with a five-run victory over Gloucestershire in front of a sell-out Cheltenham Festival crowd.

The visitors posted 157 for 8 in bright sunshine after losing the toss, Tillakaratne Dilshan making 36 off 23 balls with six fours. There were two wickets each for Will Gidman, Benny Howell and Jack Taylor.

In reply, Gloucestershire managed 152 for 7 thanks to a late blitz from Howell and Taylor, Michael Klinger top-scoring with 45. Matt Dunn finished with 3 for 37 and Zafar Ansari 3 for 27.

The result took Surrey to 16 points from their 12 South Division games, strengthening their chances of a top-two finish and a home quarter-final.

They looked set for a much bigger score when reaching 59 for 1 off the first five overs of their innings. Jason Roy had already made 11 when caught behind off the final ball of the opening over from David Payne and Dilshan and Kevin Pieterson built effortlessly on the fast start, Dilshan producing two of his trademark scooped boundaries as the pair put on 50 in 26 balls.

But the game turned when Pietersen, having just stroked his third boundary to move to 17, was bowled off an inside edge by Will Gidman in the final over of the Powerplay.

From 63 for 2, Surrey plunged to 119 for 8, mainly due to the efforts of medium-pacer Howell and offspinner Taylor after Gidman had completed a notable double by clean bowling Dilshan.

Chris Dent also played a part with his occasional left-arm spin but when skipper Klinger returned to the seam of Payne and Graeme McCarter at the end, Robin Peterson and Jade Dernbach cashed in.

The last two overs went for 30 runs, lifting Surrey spirits, and producing what looked just about a par score in the conditions. Dernbach's contribution of 24 from 14 balls was particularly valuable, though an injury was to prevent him from bowling.

Gloucestershire got off to a poor start when Alex Gidman lifted a catch to mid-on off Dunn in the first over of their innings and Dent fell in similar fashion to the same bowler to make it 15 for 2 in the third over.

By the end of the Powerplay the hosts had reached just 33 for 2. Klinger and Ian Cockbain added 51 for the third wicket but when Ansari removed Cockbain for 18 and Will Gidman in the 11th over, Surrey were well on top.

Gareth Batty, Peterson and Dilshan made up a quartet of spinners who were difficult to get away on the dry surface. Ansari had Klinger caught at long-off in the 13th over and Gloucestershire were facing a lost cause. The Australian had faced 38 balls, hitting four fours and a six, but lacked any meaningful support.

On Klinger's departure Howell came in to quickly launch three sixes, including two in the same Ansari over, but 11 an over was still needed off the last five. Howell was caught behind off Dunn for an entertaining 29, while Taylor blasted 19 off just six balls at the end when it was all too late.

"It was a great effort from the bowlers because we didn't get a great score," Surrey skipper Gary Wilson said. "The partnership between Peterson and Dernbach at the end of our innings was crucial.

"Jade has aggravated a hamstring niggle, which is why he didn't bowl. We have managed to qualify for the knock-out stage from what I consider the stronger group and would love to have a quarter-final at The Oval."

Gloucestershire captain Klinger said: "'m getting very frustrated because we keep making the same mistakes with some of the basics of T20 cricket. Surrey are a very talented side, but we were in a position to beat them today and it didn't happen."