Dimuth Karunaratne's fifth Test century boosted Sri Lanka's hopes of avoiding defeat to Bangladesh on day four of the second Test, in Colombo.
Karunaratne struck 126 off 244 balls to help the tourists to 268-8 at stumps before Dilruwan Perera dug deep to score an unbeaten 26 off 126 balls as the hosts stretched their lead to 139 runs with two wickets still in hand.
Mustafizur Rahman (3-52) and Shakib Al Hasan (3-61) picked up three wickets each as Bangladesh bid to celebrate their 100th Test match with a rare win.
Sri Lanka began the day on 54-0 only for off-spinner Mehedi Hasan to strike with his first ball of the day and dismiss Upul Tharanga (26).
Karunaratne and Kusal Mendis (36) added 86 for the second wicket as Sri Lanka stayed on course to set Bangladesh a challenging target to chase on the final day.
But Mustafizur and Shakib brought Bangladesh back into the match by inducing a mini collapse which saw the hosts reduced from 143-1 to 190-6.
Karunaratne and Perera then added 27 for the seventh wicket before the former became Shakib's third scalp of the innings.