Shakib Al Hasan and Mustafizur Rahman shared six wickets as Bangladesh closed in on a possible first ever Test win over Sri Lanka in Colombo.
The tourists bowled themselves into a strong position on day four of the second Test, despite home batsman Dimuth Karunaratne's century, as Sri Lanka led by 139 runs with just two wickets remaining in their second innings.
His hundred looked to be largely in vain as his team-mates failed to back him up on a day when Bangladesh made major strides towards squaring the two-match series and ending a run of 15 defeats and two draws in 17 previous meetings.
Karunaratne turned his overnight 25 into 126, including one six and 10 fours, as he formed a second-wicket stand of 86 with Kusal Mendis following the early loss of Upul Tharanga for 26.
Sri Lanka had begun the day on 54 without loss but following Tharanga's dismissal and that of Mendis, for 36, they failed to get into any real rhythm as Shakib (three for 61) and Mustafizur (three for 52) took charge.
Sri Lanka's wickets fell at regular intervals but it was the dismissal of century-maker Karunaratne which was a crucial blow for the tourists. The home side had taken the total to 217 when he fell victim to Shakib to become seventh wicket down in the final session of the day.
Shakib pitched a delivery outside off and when Karunaratne edged the ball to first slip, Soumya Sarkar took the catch to bring his day-long vigil to an end.
Sri Lanka also lost Rangana Herath for nine before the close as they ended the day on 268 for eight and a lead of 139.
It was left up to Dilruwan Perera (26 not out) and Suranga Lakmal (16 not out) to carry their hopes of avoiding a first defeat to Bangladesh on the final day.