Bangladesh lost three quick wickets and was struggling at 11-3 in pursuit of a victory target of 274 against South Africa after giving themselves a sight of victory in the first Test and another piece of history Sunday.
Bangladesh took nine wickets for 88 runs in the last two sessions of the fourth day to bowl South Africa out for 204 in their second innings when it looked like the home team was about to build an unassailable lead.
But just as South Africa lost quick wickets to change the complexion of the match and raise the Tigers' hopes of a first Test win over the Proteas, the Bangladesh batsmen slumped at the start of their chase.
Read:Bangladesh 298 all out, South Africa lead by 75 in 1st Test
Openers Shadman Islam (0) and Mahmudul Hasan Joy (4) and captain Mominul Haque (2) were already out for Bangladesh having hardly helped in the chase.
South Africa turned to their spin bowlers to open the bowling at the end of the day and it worked perfectly.
Keshav Maharaj collected 2-7 and Simon Harmer 1-4, and Bangladesh were in deep trouble after facing just six overs before bad light forced the umpires to call stumps.
South Africa were 116-1 in their second innings soon after lunch, 185 runs ahead and seemingly in position to build a huge advantage at Kingsmead and take the game away from Bangladesh.
But pace bowler Taskin Ahmed forced out South Africa captain Dean Elgar lbw for 64 for the crucial breakthrough, and Bangladesh's other bowlers took that cue to run through the South Africans and keep the Test alive.
Seamer Ebadot Hossain and spinner Mehidy Hasan Miraz claimed three wickets each as South Africa went from that position of strength at 116-1 to 204 all out.
Read: SA vs BAN Series 2022: Joy's Joyful knock is an Inspiration to Bangladeshi Players
The victory target of 274 meant Bangladesh had a realistic chance to win the opening Test and follow up on their historic one-day series result last month when they won a series in South Africa for the first time.
But Bangladesh's maiden Test win over South Africa is in the balance.
Offspinner Harmer had Shadman caught at slip in the second over of the innings and left-arm spinner Maharaj sent Mahmudul and Mominul packing in the fifth over.