Kumar Sangakkara became only the second cricketer to hit a triple century and a hundred in the same Test as Sri Lanka set Bangladesh a huge target of 467 to win the second and final match in Chittagong.
Sangakkara, who struck his maiden triple century in the first innings, hit a six off Sohag Gazi to reach three figures in the second and emulate former England opener Graham Gooch's 1990 feat against India at Lord's.
The 36-year-old left-hander was then bowled by the off-spinner's next delivery for 105 as he attempted to sweep on the fourth day.
Sangakkara's fluent 144-ball knock included 11 fours and two sixes, and his two-inning tally of 424 fell short of Gooch's record of 456 for most runs in a single Test.
His partner in a fourth-wicket stand of 145, Dinesh Chandimal, struck his third Test century as Sri Lanka declared on 305 for four half an hour just before the close.
Sangakkara had also been dropped on 36 by Nasir Hossain at deep mid-wicket off the bowling of Shakib Al Hasan.
'He just played to add runs, he had no such points in his head when he was at the crease,'' Sri Lanka manager Michael de Joysa said of the record of Gooch, who scored 333 and 123 against India at Lord's in 1990.
It was Sangakkara's 35th Test century, fifth best on the all-time list, and the second time he's scored two centuries in a Test, both times against Bangladesh.
Bangladesh openers Tamim Iqbal and Shamsur Rahman then survived eight overs to leave their side on 12 for no wicket.
Earlier, the home team resumed on 409 for eight but folded for 426 with spinner Ajantha Mendis claiming the last two wickets to finish with six for 99.
Mahmudullah then removed both openers and fellow spinner Shakib Al Hasan trapped Mahela Jayawardene lbw to reduce Sri Lanka to 78 for three before Sangakkara and Chandimal rallied.