Bangladesh was bowled out for 467 runs, leading Sri Lanka by 129 runs, after Mosaddek Hossain was stumped off Rangana Herath, falling for 75 runs on his Test debut.
The visitors earlier lost the remaining three wickets inside 18.1 overs in the third session.
Mosaddek and Mehedi had, after tea, batted steadily in the 131-run seventh-wicket partnership.
Mehedi Hasan fel leg-before to Herath after making 24 while Mustafizur Rahman was trapped leg-before giving Herath 1,000 first-class wickets, becoming the second man after Muttiah Muralidharan to achieve the feat from Sri Lanka.
The day belonged to Bangladesh as Shakib and Mushfiqur Rahim continued their sixth-wicket stand from the second evening, extending it to 90 runs before the captain was bowled by Suranga Lakmal.
At close of play Sri Lanka was on 54 for no loss with openers Upul Tharanga and Dimuth Karunaratne both unbeaten on 25 runs each.