The hosts lost four of their established batsmen within the 10th over reaching 34 before stumps, 107 runs behind Sri Lanka, with first innings centurions Mushfiqur Rahim (14) and Litton Das (1) at the crease at the Sher-e-Bangla National Cricket Stadium.
Sri Lanka lost their last five wickets cheaply for 49 runs, yet dominated majority of the day - kudos to Mathews and Chandimal, who played out the first two sessions without losing any wicket on Thursday.
After losing an entire session to rain the day before, the pair played into the penultimate day steadily with a safe approach as Mathews cropped up 13th Test century, his second in the series, off 274 balls - the slowest of his career.
Chandimal hit his 12th century but he had switched gears after reaching his fifty to push his team ahead at a quicker rate. Mathews remained unbeaten and played out 342 balls before Shakib Al Hasan (5-96) and Ebadot Hossain (4-148) cleaned up the tail.
Ebadot gave the breakthrough with a slower one that Chandimal sent straight to Tamim Iqbal at cover. Shakib joined the foray by taking Niroshan Dickwella (9) who fell edging a wide one back to the wicketkeeper.
The southpaw took out Praveen Jayawickrama in similar fashion after Ebadot trapped Ramesh Mendis (10) in front. Asitha Fernando (2) ran himself out to close the innings, but Sri Lanka had by then built a foundation to push for a victory.
Coming out to bat with 13 overs remaining in the day, Tamim Iqbal registered his second duck of the match when he fell to a juggling effort by Mendis at second slip off Fernando.
After Nazmul Hossain Shanto (2) dismally ran himself out, Mominul Haque registered another duck when he caught behind on review off Kasun Rajitha.
Mahmudul Hasan Joy (15) was the only Bangladeshi batsmen to show some early intent as he began with a couple of sweetly-timed flicks for boundaries.
Dropped in the fifth over in slips, Joy could not take advantage of his reprieve as Rajitha got his man with ripper that flew straight to the slips off the bat.
The pitch now offers good turn and boune off the track and though Bangladesh have a bit of batting to come, Sri Lanka will look to exploit the surface to draw out a victory away from home.