Soumya Sarkar top-scored for Bangladesh with 61 while sharing a solid opening stand with Tamim Iqbal which gave the visitors the upper hand on day two before their innings unravelled late in the afternoon.
Left-arm spinner Lakshan Sandakan claimed two wickets in two balls in the final hour as Sri Lanka reduced Bangladesh to 214-5 at the close after the latest in a string of collapses by Test cricket's newest team.
Bangladesh thought they were in a comfortable position after Soumya made his third fifty in the series in as many innings, and Tamim made 49 before being trapped lbw by Sri Lankan skipper Rangana Herath.
Sandakan then trapped Imrul Kayes plumb in front to dismiss him for 34 and then successfully reviewed a not out decision to remove nightwatchman Taijul Islam off the next ball.
Suranga Lakmal delivered a further blow to the visiting side when he removed Sabbir Rahman after he had scored 42, playing the lead role in a 62-run partnership with Imrul for the third wicket.
"Honestly I am out of ideas, the same thing happened every time," said Bangladesh's batting coach Thilan Samaraweera.
"When we start to collapse we cannot control it. Tomorrow is a new day, hopefully we can get close to Sri Lanka's score."
Shakib Al Hasan lived dangerously to see out the day with unbeaten 18 alongside skipper Mushfiqur Rahim, who was on two at the close.
- 'Top Test ton' -
==================
Chandimal, who was unbeaten on 86 overnight, made 138, his eighth in Test cricket, off 300 balls after an innings which contained more than its share of good fortune.
"I rate this is as my number one century in Test cricket so far because I batted four sessions -- I've never batted four sessions in my Test career," Chandimal said after the day's play.
"We were in a tough spot with three wickets down for 30-odd. I had a responsibility at the time to think about how I can take the team beyond 250."
Soumya managed to grasp the catch after several fumbled attempts but Chandimal and Lakmal then continued to frustrate Bangladesh as they put on a 55-run partnership for the ninth wicket.
Off-spinner Mehedi finally dismissed Chandimal, who now has four Test centuries against Bangladesh in six Tests, as debutant Mosaddek Hossain took the catch at midwicket.
Chandimal, who struck only four boundaries on the opening day while helping his side recover from 70-4, batted aggressively on the second day to hit 10 fours and a six overall in his innings.
Mehedi finished with 3-90 for Bangladesh.
