Glamorgan 23 for 0 and 116 (Douthwaite 30*, Payne 5-31) trail Gloucestershire 181 (Higgins 48, Wagg 3-38) by 42 runs
A five-wicket haul by David Payne put Glamorgan into rescue mode ahead of the final day of their Bob Willis Trophy match against Gloucestershire in Cardiff.
Glamorgan, in their second innings after bowling Gloucestershire out for 181 in their first, will resume on 23 for 0, a deficit of 42 runs, on Tuesday.
Payne, Gloucestershire's left-arm seamer, again proved a nemesis when he produced a superb spell in the morning session to dismiss the home team for a modest first-innings total of 116 in 59.3 overs.
The 29-year-old Payne, who ended with figures of 17-7-31-5, took four of the five wickets to fall after Glamorgan had resumed on 80 for 5, has a formidable record against the neighbours across the Severn Bridge, having taken 58 wickets in nine years against them in all formats.
He was well supported by the other seamers, notably Josh Shaw, the former Yorkshire paceman who ended with 3 for 13 from his 9.3 overs.
Dan Douthwaite was the only Glamorgan batsman to withstand the visitors' accurate attack, and after defending well, opened up towards the end of the innings to score an unbeaten 30.
Gloucestershire also struggled at the start of their innings, losing Chis Dent in the second over, when he feathered a catch to the wicketkeeper, although he clearly felt the ball had struck his arm as he trudged back to the pavilion.
His opening partner Ben Charlesworth, experienced a torrid time against the new ball and after padding up to numerous deliveries that were close to the off stump, the tactic brought about his downfall, when he padded up to Graham Wagg and was out leg before - after facing 67 balls for his eight runs.
Graham van Buuren, meanwhile, played every ball on its merit and shared a useful partnership with Tom Lace, who was making his Gloucestershire debut after signing from Middlesex. They put on 43, before van Buuren, who had scored 32, was bowled playing inside a delivery from Timm van der Gugten.
With the visitors' score on 89 for 3, a heavy shower curtailed play, and an early tea was taken with Lace on 37 and George Hankins 3.
Gloucestershire lost a fourth wicket soon after the lengthy interval, when Hankins was caught at second slip by Nick Selman off Wagg, who had returned to the attack in place of van der Gugten, who had left the field with a dislocated finger.
Lace and Ryan Higgins had begun to look comfortable and on course to lead their side to a first-innings lead when Wagg struck again to remove the former, caught low down by keeper Cooke, with the scores level.
Gareth Roderick departed soon afterwards, caught behind swinging wildly to a wide Douthwaite delivery outside off-stump.
Rotating the three pace bowlers in van der Gugten's absence, Glamorgan turned to Marchant de Lange, who duly delivered to remove George Scott when he edged behind to a rising delivery.
Higgins, amid flurry of heaves off spinner Kieran Bull, was caught at deep square leg by de Lange as the visitors lost their eighth wicket on 173, and their ninth on 181, when Shaw was held low down at slip by Selman off de Lange.
The innings concluded when Payne was caught by Bull from his own bowling, the visitors all out for 181, a lead of 65.
Glamorgan had 14 overs to face in the final session, and openers Selman and Charlie Hemphrey guided them to the close.