Bangladesh, trailing by 389 runs in the first innings, were bowled out for 299 in the final session of the third day's play to give the hosts a decisive 2-0 lead in the three-match series.
But Bangladesh captain Mohammad Ashraful and teenager Mushfiqur Rahim frustrated the hosts by adding 191 for the sixth wicket, their country's best ever Test partnership.
The 22-year-old Ashraful, leading the side in his first series, remained unbeaten on 129, his fourth Test century and the third against Sri Lanka. He hit 18 boundaries.
Rahim, 18, who replaced long-serving wicket-keeper Khaled Mashud for this match because of his batting abilities, justified his selection with 80.
The young duo surpassed Bangladesh's previous best partnership of 187 by Habibul Bashar and Shahriar Nafees for the second wicket against Australia in Fatullah last year.
It was left to prolific off-spinner Muttiah Muralitharan, kept wicketless for 26 overs, to break the partnership after tea when he accepted a