Gloucestershre 309 for 9 dec (Gohar 86, O Price 76, Roland-Jones 5-79) and 236 for 6 (Hammond 78, Bracey 56) beat Middlesex 377 (Davies 91, Holden 77, De Caires 64, T Price 5-81) and 165 (Robson 50, Bailey 4-30) by four wickets
It was Gloucestershire’s second successive red-ball win at Lord’s, lifting them to fifth place in Division Two, while the home side drop to third and trail Yorkshire, in the second promotion spot, by 15 points.
Middlesex applied pressure during the early stages as Toby Roland-Jones opened up with a maiden and Ryan Higgins struck with his fourth delivery, searing back down the slope to trap Ben Charlesworth in front for a duck.
Opening partner Cameron Bancroft soon followed suit, lbw to a ball that Higgins moved the other way, but Hammond started to score freely against the change bowlers, pulling Tom Helm over the short boundary for six.
The left-hander added a valuable 41 in tandem with Ollie Price before Helm made the breakthrough, having the latter caught low at first slip to bring Bracey to the middle on a pair.
Bracey banished that prospect by carving Henry Brookes for successive off-side boundaries and added two more off Helm’s next over as Gloucestershire started to settle down again, going to lunch at 101 for 3.
There was a scare for Bracey soon after the interval, when he slashed outside off stump at Helm and the ball flew fast and high to Robson at slip but, despite getting both hands to it, the fielder was unable to cling on.
It was Hammond who won the race to 50 with his partner, reaching the landmark from 100 balls by drilling Higgins to the cover fence and Bracey was not far behind, using up 20 fewer deliveries in posting his half-century.
Having swept Luke Hollman for successive fours to raise the century partnership, Hammond (78) looked on course for a ton of his own until he attempted a repeat of the stroke to De Caires and skied to mid-on.
With Graeme van Buuren given out caught behind two balls later and Bracey sweeping into the hands of deep midwicket for 56, Gloucestershire suddenly found themselves six down and under renewed pressure.
De Caires (3 for 45) continued to test the batters with flight and turn, but Price eased the tension by on-driving Roland-Jones to the boundary to take Gloucestershire beyond 200 and he and Zafar advanced steadily towards the finish line.
Zafar, who had top-scored with 86 in the first innings, applied the finishing touch as he struck a De Caires full toss to the fence to finish unbeaten on 19, with Price alongside him on 34.