The prospect of Gloucestershire passing 400 looked remote when they lost their overnight pair in the space of four overs to leave them 301-8.
Miles Hammond added only five before a brilliant diving one handed catch by Ben Aitchison at second slip in the third over of the morning removed him for 145.
Aitchison then brought one back to deceive Ed Middleton (46) who shouldered arms and lost his off stump.
But that was Derbyshire’s last success of the session with Brookes and Williams first denying them a third bowling point and then growing in confidence as the hosts lost their way.
Williams twice dispatched Bashir over the ropes, the second a one-handed slog-sweep into the car park, and by lunch, the pair had added 90 from 140 balls.
There was no respite for the home side after the interval with the previous highest ninth wicket stand of 99 for Gloucestershire against Derbyshire quickly eclipsed before Brookes and Williams opened up against the spinners.
Bashir was smashed for consecutive sixes by Brookes and the all-time ninth wicket record was within touching distance when the England man had the last word.
Brookes tried to pull Bashir over midwicket but got a big top edge and Brooke Guest took the catch to end a memorable partnership.
It was now a question of whether Williams could reach a maiden century but in trying to keep the strike, he was run out by Aitchison’s return from deep point which beat his despairing dive.
That left Derbyshire a tricky period to negotiate before tea and they lost a wicket to the final ball of the first over when Gabe Bell angled one in to have Harry Came lbw for eight.
The day got even better for Williams who trapped Montgomery (28) half forward before Caleb Jewell was beaten by a ball that spun back from Graeme Van Buuren and bowled off his pad, also for 28.
Madsen tucked into some loose bowling from Ben Charlesworth but Gloucestershire could have ended the day on a high if Cameron Bancroft had not dropped the Derbyshire skipper on 38 at second slip.
Report by ECB Reporters’ Network, supported by Rothesay.








