Jacques Kallis emerged as the unlikely bowling hero for the South Africans after he took five of the six wickets to fall in the morning session and limit the lead to 204 on a deteriorating track at the Sher-e-Bangla stadium.
Kallis finished with figures of 5-30 off 14 overs, his fifth five-wicket haul in Tests.
The prolific all-rounder gave the Proteas a crucial breakthrough when he had the well-set Junaid Siddique caught behind for a patient 74 that came off 184 balls and contained six fours.
Siddique's dismissal triggered a collapse with Dale Steyn trapping leg before the other overnight batsman Aftab Ahmed for 24 and Kallis returning to send back wicketkeeper batsman Mushfiqur Rahim (two).
The three dismissals in the space of three overs turned the tide slightly in favour of South Africa whose earlier highest successful run chase in the sub-continent was 164 against India in Mumbai in 2000.
Kallis, hit by two fours on the trot by the retiring Mohammad Rafique, had the last laugh when he had his off-stump uprooted in spectacular fashion.
Rafique will retire after the conclusion of this two-Test series.
A sweetly timed boundary by tailender Mashrafe Mortaza was wildly cheered by expectant home crowd, who came in greater numbers Sunday in the hope of a historic win by the Tigers.
But it was a rare highlight for the home team, as Kallis cut short the Bangladesh innings.
Bangladesh, who lost all their previous four encounters against South Africa by innings margins, have won just one of their 51 Tests -- against minnows Zimbabwe.