The visitors started the third day on 214-5 and reached 428 for seven at tea, 90 runs ahead of Sri Lanka's score of 338 at the P. Sara Oval.
Shakib was out for 116 runs just before the interval, but Mosaddek remained unbeaten on 55 as Bangladesh bid to mark their 100th Test match in style.
Shakib's 131-run seventh wicket stand with Mosaddek was broken when the left-hander lofted a catch to Dinesh Chandimal at midwicket off the bowling of Laksman Sandakan.
Bangladesh captain Mushfiqur Rahim earlier made 52 as he shared a 92-run sixth wicket partnership with Shakib to help revive the tourists' innings after a shaky end to their run chase on day two.
The visitors lost three wickets in the space of seven balls in the final half-hour on Thursday but Mushfiqur was his usual composed self on Friday morning as he brought his 17th Test half-century with a glorious off-drive off Dilruwan Perera through extra cover.
Mushfiqur survived a close shout for lbw after completing his fifty before Lakmal broke through his defence with an in-swinger that kept low.
Shakib, who rushed to 18 off eight balls on Thursday afternoon, completed his 50 off 69 balls with a single off Lakmal after surviving a run out while on 40.
He hit 10 boundaries overall in his 159-ball innings, bringing up his century by sweeping Dilruwan Perera to the boundary.