Pakistan's experienced batsman Younis Khan dug deep for his 24th test century and his seventh against Sri Lanka to rescue his struggling side, who closed on 261-4 on the opening day of the first test on Wednesday (local time).
Younis and his captain Misbah-ul-Haq (31) put together a partnership of 100 for the fourth wicket to stage a recovery after Sri Lanka grabbed the first three wickets for 56 runs.
Following Misbah's departure in the final session, Younis was joined by Asad Shafiq and they carried the total to 261 by the close after an unbeaten stand of 105.
Younis was on 133 off 228 balls with 11 fours and a six while Shafiq had 55 off 110 balls with six fours and a six.
Herath broke up the Younis-Misbah pairing when the Pakistan captain drove at a tossed up delivery and edged the ball to wicketkeeper Niroshan Dickwella in the fourth over after tea.
Seasoned campaigners Younis and Misbah had worked hard to rebuild Pakistan's innings with an unbroken 84-run fourth wicket stand that guided the tourists to 140 for three at tea.
Younis reached the interval on 77, after his 29th test fifty, and Misbah on 22 as they batted through the afternoon session to add 81 runs after Pakistan lost three early wickets.
Both batsmen rode their luck with Younis benefiting the most, surviving two lbw decisions and a dropped catch to hit five fours and a six in his 146-ball knock.
Soon after lunch, Misbah and Younus survived lbw appeals off the bowling of Sri Lanka captain Angelo Mathews.
Misbah had yet to score when a delivery hit him on the front pad but the Pakistan skipper was given not out. Sri Lanka called for a review which backed up the umpire's call.
In his next over, Mathews jagged one back at Younis, on 20, hitting him on the back foot in front of the wicket but Sri Lanka opted against a review with television replays suggesting the ball would have gone on to hit the middle stump.
Younis then used a review to survive another lbw decision on 59, this time against Dilruwan Perera, who he had hit for three consecutive fours in a 14-run over to reach his half-century.
Younis got a fourth life on reaching 68 after he reverse swept Perera to Mahela Jayawardene at slip but the fielder could not hold on to the difficult chance.
Earlier, Sri Lanka paceman Dhammika Prasad struck two early blows as Pakistan reached lunch on 59-3 after Misbah had won the toss and opted to bat.
After a delayed start due to a wet outfield, Pakistan lost both openers to Prasad within the first hour of play, during which they managed just 22 runs.
Prasad, coming in for the injured Suranga Lakmal, troubled Pakistan's batsmen with his pitched up inswingers.
He had Ahmed Shehzad (four) playing on to a delivery with the team's score on four and later trapped Khurram Manzoor leg before for three to reduce Pakistan to 19-2.
Younis joined Azhar Ali in a partnership of 37 before Rangana Herath separated them, removing the latter for 30 with a fine delivery that beat the bat and kissed the off stump.
What do you make of the recent crackdown on chucking in cricket?