Marcus North took four wickets as Glamorgan gave themselves a chance of victory against Hampshire on the third day of their LV= County Championship Division Two match at the SWALEC Stadium.
After Gareth Rees completed his first championship century for 26 months, the hosts declared their first innings on 300 for six - 41 behind Hampshire.
But the visitors subsided to 53 for six before Neil McKenzie scored a vital half-century in a 101-run partnership with Sohail Tanvir; by the close, they had reached 174 for nine - an overall lead of 215.
Hampshire's troubles began when Stewart Walters hung on to a brilliant one-handed slip catch that dismissed Michael Carberry for a duck.
It got better for Glamorgan as North's off-spin accounted for two wickets in an over; Mark Wallace stumped Jimmy Adams before Liam Dawson was bowled.
From 28 for three, Hampshire found themselves 50 for four when James Vince was run out by a Michael Hogan direct hit.
Sean Ervine and Adam Wheater went in the space of four balls as Hampshire limped to tea at 75 for six - a lead of 116 - but Tanvir took the attack to Glamorgan when hitting sixes in successive overs from Jim Allenby and Dean Cosker.
Already missing seamer Will Owen through injury, the Welsh county suffered a second setback when paceman Michael Reed pulled up while bowling.
However, McKenzie gave a sharp return catch to Allenby, who also caught Tanvir at slip off North. In the last over, David Balcombe was bowled by North, the tweaker enjoying figures of 4-27.
Rees' century helped Glamorgan, who resumed their first innings on 196 for three, and it was quite a moment given he had not reached three figures in the championship since May 2011.
In the end, Rees was the first man to fall today, ending a 271-ball and 341-minute stay in the middle; he edged Balcombe to Dawson at second slip.
That left Glamorgan 266 for four and, without addition to the score, Murray Goodwin fell 14 runs short of a third Glamorgan century, trapped lbw by Tanvir - who ousted skipper Wallace in the same fashion for a duck.
Glamorgan declared their second innings on 300 for six two overs after lunch in a bid to set up a game - a decision that paid dividends.