Dimuth Karunaratne scored his maiden double hundred as Sri Lanka batted through the day without losing a wicket Saturday to match Bangladesh's 500-plus score in the first Test.
The Sri Lankan captain ended the fourth day on 234 while middle order batsman Dhananjaya de Silva moved to 154 as the home side reached 512 for three at stumps, still 29 runs behind Bangladesh's first innings total.
They have added 322 runs for the fourth wicket, the highest stand at Pallekele for any wicket. The previous best was by Australia's Mike Hussey and Shaun Marsh, who made 258 in 2011, also for the fourth wicket.
Karunaratne passed his career best score of 196, set against Pakistan in 2017, by elegantly driving Taskin Ahmed for four and in the same over reached his first double ton.
The 33-year-old left-hander has now been at the crease for more than 11 hours and faced 419 deliveries, 25 of which have been boundaries.
Bangladesh took the second new ball in the morning but after failing to make a breakthrough with his seamers, captain Mominul Haque reverted back to spin.
After lunch, de Silva reached his seventh Test hundred by pulling Taskin Ahmed for four. He has faced 278 deliveries and hit 20 fours.
Bangladesh gave away several overthrows and misfields which helped the score.
The game suffered one 29-minute hold-up due to bad light after tea. The players returned briefly but were taken off again in fading light and never went back. A total of 22 overs were lost.