Bangladesh's Soumya Sarkar and Tamim Iqbal shared a century opening stand before Sri Lanka took two late wickets to tighten their grip on the first Test at Galle on Wednesday.
The visitors were 133-2 at stumps on the second day and trailing by 361, after Kusal Mendis (194), Niroshan Dickwella (75) and Dilruwan Perera (51) had swelled the hosts' total to 494.
Soumya was leading the response for Bangladesh with an unbeaten 66 after his 118-run opening stand ended with a bizarre run-out for his partner, Tamim, who made 57 off 112 balls with six fours.
Sri Lankan wicketkeeper Niroshan Dickwella had appealed for a caught behind off Lakshan Sandakan and dislodged the bails quickly once his appeal was turned down as Tamim walked out of the crease.
Bangladesh coach Chandika Hathurusinghe, echoing Australia's Steven Smith on another occasion, said Tamim appeared to have had "a brain fade".
"He hasn't spoken to me yet but... (we were) very disappointed because we were cruising at that time," he told reporters.
Perera then had number three Mominul Haque plumb lbw for seven to give Sri Lanka the edge in the contest at the Galle International Stadium.
Both Soumya and Tamim benefited from sloppy Sri Lankan fielding. Perera dropped Soumya on four at gully and Dickwella missed a catch off Tamim on 28.
Earlier, Mendis was agonisingly denied a maiden double century as he tried to reach his milestone in style.
Tamim caught him on the long-on boundary off teenage off-spinner Mehedi Hasan as the right-hander attempted an audacious six.
- Wonder catch -
Tamim ran backwards to take the catch, lobbing the ball back into the field as his feet crossed the boundary ropes and then pouching it again.
Mendis struck 19 fours and four sixes in his seven-and-a-half-hour stay at the crease.
The 22-year-old, who was unbeaten on 166 overnight, was earlier granted a reprieve by a no-ball on the first delivery he faced.
He was also almost dismissed when he struck his first six of the morning, as Mustafizur Rahman took a catch off the bowling of Subashis Roy but stepped on the rope on the fine leg boundary.
"I wanted to hit a six and be positive. It's a batting pitch," Mendis said after the day's play.
"It keeps low and I just wanted to play straight or use the sweep.
"I felt really bad when I edged first ball, but... it was a no-ball and that was nice," he said.
Spinner Mehedi ended with four wickets for 113 runs. Apart from Mendis, he dismissed Dickwella when the wicketkeeper-batsman gave a catch to Mahmudullah at midwicket after making 75 off 76 balls.
Dickwella, who hit six fours and a six in his quick-fire innings, put on 110 with Mendis for the fifth wicket off just 124 balls.
Mustafizur then removed Rangana Herath for 14 and Suranga Lakmal was run out for eight to give Bangladesh some respite.
Mehedi trapped Perera leg-before on 51 before taking a stunning catch off Shakib Al Hasan to send last man Sandakan packing.