Kumar Sangakkara missed out on a double hundred by one run but his team ended the second day of the first Test on a high with Pakistan reeling at 48 for five at the close on Saturday.
Sri Lanka were dismissed for 472 shortly after tea with Sangakkara stranded on 199 not out made off 387 balls and including 18 fours and two sixes.
Pakistan were rocked by Nuwan Kulasekara who snapped up the wickets of Taufiq Umar lbw for nine and Azhar Ali for a golden duck caught behind by Prasanna Jayawardene.
Stand-in skipper Mohammad Hafeez and Younis Khan took the score to 43 when off-spinner Suraj Randiv made a double strike by trapping Hafeez lbw for 20 and sending back nightwatchman Saeed Ajmal caught first ball off bat and pad by Tharanga Paranavitana.
Left-arm spinner Rangana Herath joined the party when he forced Asad Shafiq to edge a catch behind the wicket to Jayawardene for a duck.
At stumps Younis Khan was unbeaten on 15 and Mohammad Ayub on one.
Sri Lanka's innings was built around Sangakkara's 29th Test hundred which nearly brought him joint second on the all-time list with West Indian Brian Lara on nine Test double hundreds.
A blunder by the scoreboard had Sangakkara celebrating his double century with when he slog-swept Ajmal for six but actually his score was 199.
When told by his team mates that he still required one run he tried desperately to steal a single off the final ball of the over but failed.
That left last man Nuwan Pradeep exposed to Hafeez and after defending the first ball Pradeep was bowled to end the Sri Lanka innings.
Pakistan fought back in the afternoon session through their spinners to restrict Sri Lanka to 439 for eight at tea.
Sri Lanka scored 73 runs and lost three wickets, squandering some of their advantage having resumed the day on a commanding 300 for two.
Off-spinner Hafeez broke a threatening sixth-wicket stand of 80 between Sangakkara and Prasanna Jayawardene (48), who drove at a ball that spun and offered an outside edge to wicketkeeper Adnan Akmal.
Left-arm spinner Rehman caught Suraj Randiv (eight) off his own bowling and Hafeez picked up his second wicket when he removed the scoreless Kulasekara on the stroke of tea.
The morning session was dominated by Ajmal who claimed his sixth five-wicket haul in Tests with figures of five for 146.
The 34-year-old spinner captured three wickets for 10 runs off 22 balls.
Pakistan's new ball bowlers Umar Gul and Junaid Khan once again toiled without luck, prompting Hafeez to introduce Ajmal after seven overs of seam and the spinner did not let down his skipper.
The top-ranked Test spinner struck a crucial blow when he bowled Mahela Jayawardene for 62 when the Sri Lanka captain fluffed a slog-sweep.
The spinner then lured Thilan Samaraweera (six) out of his crease with a doosra to get him stumped and Ajmal caught Angelo Mathews for a duck from the next delivery.