Daniel Douthwaite inspired a Glamorgan fightback to set up an intriguing finale to the Division Two match against Derbyshire after Ravi Rampaul had celebrated his first five wicket haul for three years.
The West Indian seamer claimed 5 for 94 as Glamorgan were bowled out for 346, 32 runs behind, with Billy Root scoring 68 and Douthwaite 39 in his first championship innings.
Derbyshire were going well at 96 for 1 but they lost seven wickets for 60 runs with Douthwaite taking four in five overs, and closed on 171 for 9, a lead of 203.
Glamorgan’s success in denying Derbyshire a bigger lead was largely down to a seventh wicket stand of 72 in 29 overs between Douthwaite and Tom Cullen.
When Luis Reece nipped one back to trap Root lbw, Glamorgan were still 143 runs adrift but Douthwaite and Cullen showed restraint and resolve to get through the second new ball.
Derbyshire gave little away and two dropped slip catches did not prove expensive but the batsmen did well until Rampaul had Douthwaite caught behind for 39.
Cullen quickly followed, well taken at second slip for 40, and Rampaul secured a third bowling point when he yorked Andrew Salter in the 110th over.
But Lukas Carey landed some uncomplicated blows, launching Reece into the seats in front of the pavilion, before his attempt to put Rampaul onto the ring road ended in the hands of deep midwicket to give him his maiden Derbyshire five wicket bag.
Derbyshire started their second innings poorly with skipper Billy Godleman again failing when he was caught behind down the leg side off Michael Hogan for nine, but Wayne Madsen and Reece raised the tempo before a clatter of wickets checked their progress.
Madsen edged David Lloyd to second slip and Reece went the same way in his next over before Alex Hughes chipped Carey to square leg.
When Harvey Hosein was caught by Cullen diving full length, the contest was wide open and Douthwaite struck twice in four balls.
Tom Lace chopped on trying to steer to third man and Matt Critchley walked across and was lbw before Logan van Beek top edged a pull and was caught behind.
Hogan returned to bowl Tony Palladino and it needed two firm blows from Rampaul to take Derbyshire’s lead past 200 before stumps were drawn at 7.15pm.