Bangladesh lost three wickets in quick succession on the fourth day of the first Test against South Africa at Kingsmead.
Bangladesh, chasing a target of 274 to win, were teetering at 11-3 at the close, with Proteas spinners Simon Harmer and Keshav Maharaj taking all three wickets inside five overs with the new ball.
Off-spinner Harmer had Shadman Islam caught at slip for nought in the second over before left-armer Maharaj took two wickets in his third over.
Maharaj bowled first innings century-maker Mahmudul Hasan Joy for four with a ball that drifted in and found a gap between bat and pad.
Bangladesh captain Mominul Haque edged two runs before he went back on his stumps and was trapped lbw.
The late afternoon collapse undid much of the good work Bangladesh had done with a superb bowling and fielding performance earlier in the day.
South Africa appeared to be in control of the match when they reached 105-1 at lunch in their second innings.
But Bangladesh came back strongly to bowl out the home side for 204.
Fast bowler Ebadot Hossain took 3-40, while off-spinner Mehidy Hasan took 3-85 in 35 overs.
Proteas captain Dean Elgar made 64, his second half-century of the match, and newcomer Ryan Rickelton was stranded on 39* when the last three wickets fell for two runs in seven balls.
Mehidy bowled with excellent control, as he had in the first innings, which enabled Mominul to use his fast bowlers in short spells.
Bangladesh took four wickets and conceded only 52 runs in 28 overs between lunch and tea.
Elgar, who made 67 in the first innings, was dropped in the slips twice, on 34 off Mehidy Hasan and on 43 off Ebadot.
But Bangladesh made up for the errors with outstanding catches by Yasir Ali at slip and Shadman at silly mid-off, while substitute Nurul Hasan pulled off a direct hit run-out of Harmer with a throw from the cover boundary.
© Agence France-Presse