Kumar Sangakkara joined Graham Gooch as the only batsmen to make a triple century and century in the same Test before Sri Lanka set Bangladesh a target of 467 to win in Chittagong.
Sangakkara made 105 in Sri Lanka's second innings of 305-4 declared, to add to his first-innings 319, thus becoming only the fourth player to score 400 runs in a single Test.
Dinesh Chandimal finished 100 not out before Sri Lanka's declaration late on day four and Bangladesh, who need a win to earn a share of the two-match series, reached 12-0 at stumps.
Ajantha Mendis had claimed the final Bangladesh first-innings wicket in the morning to finally dismiss the home side for 426 before their opponents set about extending their advantage of 161.
Mahmudullah slowed them early on, taking the wickets of openers Dimuth Karunaratne, caught at first slip by Nasir Hossain for 15, and Kaushal Silva, who went lbw for 29.
Sangakkara proved their nemesis again, though, as he plundered another ton, hitting two sixes and 11 fours in his 144-ball knock before becoming the fourth man out, bowled between bat and pad by Sohag Gazi.
It saw him join Graham Gooch (456), Mark Taylor (426) and Brian Lara (400) as the only players to reach 400 in a Test.
Sri Lanka had already lost Mahela Jayawardene for only 11, Shakib Al Hasan with the wicket, but Sangakkara and Chandimal combined for a partnership of 145 which all but ended Bangladesh's slim victory hopes.
Angelo Mathews joined Chandimal when Sangakkara finally went, making a swift 43 before the tourists decided they had enough.
Tamim Iqbal was on seven and Shamsur Rahman on four in the early stages of the hosts' reply at the close.
Sri Lanka won the first of the two-match series by an innings and 248 runs in Dhaka.