Mominul Haque and Mahmudullah hit half-centuries to enable Bangladesh to avoid the follow-on but their total of 320 was still 176 short of South Africa's first innings total of 496 for three declared.
In contrast to the first day, Bangladesh dismissed both South African opening batsmen cheaply at the start of the second innings.
Mominul made 77 -- the highest Test score by a Bangladesh batsman against South Africa -- and Mahmudullah hit 66 as Bangladesh topped 300 for the first time in nine Test innings in South Africa, where they have lost all four previous Test matches by an innings.
On a slow pitch, Bangladesh had four successive half- century partnerships between the third and sixth wickets.
The tourists batted with positive intent, although much of the good work was undone when they lost their last five wickets for 28 runs, four of them after the second new ball had been taken.
The diminutive Mominul and fellow left-hander Tamim Iqbal saw off some hostile bowling by Morne Morkel and Kagiso Rabada at the start of the day, with the first nine overs producing only seven runs.
Both batsmen survived close leg before wicket decisions against reverse-swinging deliveries from Rabada. But 17 runs came off Rabada's fifth over of the day, including two successive boundaries by Mominul, and South Africa's change bowlers were unable to maintain the pressure.
The only wicket of the morning fell to new cap Andile Phehlukwayo when Tamim, on 39, glanced an off-target delivery down the leg side and wicketkeeper Quinton de Kock flung himself to his right to take a good catch.
Mominul was well caught at short leg by Markram off left-arm spinner Keshav Maharaj soon after lunch after a 150- ball innings which included 12 fours.
Mahmudullah, strong on the drive, found another useful ally in Sabbir Rahman (30) before both batsmen were dismissed in quick succession.
Rahman played a lifting ball from Duanne Olivier onto his stumps and Mahmudullah fell to the first delivery with the second new ball when an attempted cut against Morkel crashed into his stumps off an inside edge. Mahmudullah faced 124 balls and hit 11 fours and a six.
Maharaj was the most successful South African bowler, taking three for 92.
(This story has not been edited by Business Standard staff and is auto-generated from a syndicated feed.)