The visitors were all out for 467 runs to establish a 129-run lead in the first innings over their Sri Lankan hosts, who were bowled out for 338 on the previous day at the P. Sara Oval.
Sri Lanka reached 54-0 at stumps on the third day with both openers Dimuth Karunaratne and Upul Tharanga unbeaten on 25 to reduce the gap to 75 overnight.
Shakib made 116 and received strong support from Mosaddek (75) and skipper Mushfiqur Rahim, who scored 52 as Bangladesh put in one of their most impressive batting performances in their 100th Test match.
The Bangladeshi lead looked like it was going to be even bigger at one stage before Sri Lankan skipper Rangana Herath polished up the last three wickets for 13 runs and finished with 4-82.
Herath -- Test cricket's most successful left-arm spinner -- in the process became only the second Sri Lankan after Muttiah Muralitharan to claim 1,000 first-class wickets.
Left-arm spinner Lakshan Sandakan also impressed among the Sri Lankan bowlers, finishing with figures of 4-140.
It was Sandakan who ended Shakib's 131-run seventh wicket stand with Mosaddek when the Bangladesh talisman lofted a catch to Dinesh Chandimal at midwicket.
Skipper Mushfiqur earlier 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.
Mosaddek then added 33 runs with Mehedi Hasan (34) to stretch Bangladesh's advantage before Herath underlined his quality.
Bangladesh's innings ended when Mosaddek was stumped by wicketkeeper Niroshan Dickewella after hitting seven fours and two sixes in his debut Test knock.
(This story has not been edited by Business Standard staff and is auto-generated from a syndicated feed.)