Bangladesh struck early in the morning session when Mehedi Hasan Miraz got Upul Tharanga (26) with a beautiful turner with his first ball. Since then Bangladesh bowlers struggled to trouble the batsmen.
Mendis, who scored 194 in the first innings at Galle, looked comfortable in patiently negotiating some sharp turners from Bangladesh spinners while Subashis Roy and Mustafizur Rahman produced good bounce from the pitch.
The tourists, however, turned the tables on Sri Lanka who slipped to 199/6 in 69 overs at tea after managing just 62 runs at the expense of five wickets in the second session.
Mustafizur accounted for the wicket of Mendis (36) when Bangladesh overturned an on-field decision for caught behind through review. The third umpire concluded that there was a slight deviation and a noise to adjudge him out.
The end of the 86-run second-wicket stand triggered a slide. Mustafizur then sent back the last innings centurion Dinesh Chandimal (5) and Dhananjaya de Silva (0) also caught behind while Shakib snared the wickets of Asela Gunaratne (7) and Niroshan Dickwella (5).
Skipper Mushfiqur Rahim contributed with four catches behind the stumps, including two stunners.
Karunaratne, however, held his ground at one end, getting an outside edge off Mustafizur for four to reach his century off 168 deliveries, containing nine boundaries and a six.
Brief scores: Sri Lanka 338 & 268/8 (Dilruwan Pereira 26 not out, Suranga Lakmal 16 not out, Mustafizur Rahman 3/52, Shakib Al Hasan 3/61) vs Bangladesh 467