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.
The 36-year-old middle-order batsman, who came to bat in his 90th Test at 19-2, hit 11 boundaries and a six in his 24th century.
Only Inzamam-ul Haq (25) has more Test hundreds for Pakistan.
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 Younis 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.
Pakistan's coach Waqar Younis said he was delighted at the total his team was able to post after the early setbacks.
"Any coach or captain will be proud of that," the former fast bowler said. "It all boiled down to experience. Younis has tons of it and so does Misbah.
"There was a lot of talk at home of whether Asad Shafiq deserved to be in the side. He showed today that he belongs to the highest level."
Waqar said it was a bold decision by the team management and the captain to bat first despite favourable overcast conditions for the bowlers.
"With so much rain around, there is bound to be some juice in the wicket and I thought we were very bold to bat first. That paid off because the wicket eased up by afternoon."
Sri Lanka's coach Marvan Atapattu admitted it was hard work for the bowlers after the morning session.
"The moisture dried up and it became easy to bat out there," he said. "I think we have done well to keep them down to 261, but a lot still remains to be done.
"This is a wicket that usually plays well on the first two days, but spin is going to be a factor later in the match."
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.
Pakistan recovered from a dreadful start to reach 261-4 at close thanks to a magnificent unbeaten century by Younis Khan (133) and Asad Shafiq (55).
Shafiq punches Herath through the covers for a boundary as stumps are drawn with Pakistan 261-4 in 8 overs.
Younis crunches Mathews through the covers for a boundary and brings up the century partnership for the fifth wicket with Shafiq with a single. Pak 257-4.
Shafiq slams Prasad past mid-on for a boundary and reaches his ninth Test half century with a single. Pak 250-4.
The second new ball has been taken with Pakistan 240-4 in 80 overs.
Younis gives himself room and drives Herath through the covers as Pakistan step up the tempo. Pak 224-4.
Vithanage comes into the attack and goes for plenty with Shafiq pulling him round for a boundary. Pak 209-4.
Shafiq cracks Mathews through point for a boundary and survives an appeal for a catch behind. Pak 198-4.
Younis completes his 24th Test century by whipping Mathews for a single as the rain clouds loom.
Younis moves to 95 with a silky drive through the covers for another boundary off Prasad. Pak 187-4.
Shafiq becomes aggressive taking on Herath smashing a six over the bowler's head and cracking a boundary. Pak 183-4.
Shafiq hits his first boundary pulling Prasad to midwicket. Pak 169-4.
Younis reaches the 90s with a sweetly timed boundary through the covers off Herath. Pak 164-4.
Herath breaks the century partnership with a tweaker which caught the outside edge of Misbah for a catch behind. Pak 156-4 in 57.4 overs.
Misbah-ul-Haq c Dickwella b Herath 31 (100b 2x4 0x6)
Younis and Misbah bring up their 10th 100-run partnership in 30 innings together. Pak 156-3.
Younis punches Eranga through the covers for a boundary in the first over after tea. Pak 148-3.
Younis Khan hit an unbeaten half-century in the company of skipper Misbah-ul Haq to help Pakistan recover in the first Test against Sri Lanka in Galle on Wednesday.
The pair batted through the afternoon session of the opening day to put on an unbroken stand of 84 for the fourth wicket and steer the tourists from a shaky 56-3 to 140-3 by tea.
Khan, playing his 90th Test, returned unbeaten on 77 with five boundaries and a six. Misbah was on a typically dour 22 off 87 balls.
Khan was reprieved by the Decision Review System (DRS) when he was on 59 after umpire Bruce Oxenford had declared him leg-before to off-spinner Dilruwan Perera.
Television replays showed the ball passing over the stumps.
The partnership between Pakistan’s two elder statesmen came after the morning session belonged to Sri Lanka with three quick wickets in the bag.
Younis Khan (77) and Misbah ul Haq (22) were unconquered during the afternoon session to take Pakistan to 140-3 in 54 overs.
Misbah hits his second boundary driving Eranga straight down the ground. Pak 135-3.
Younis hammers the first six of the match with a slog sweep off Dilruwan and is let off by Mahela at slip attempting a reverse sweep. Pak 122-3.
Pakistan successfully overturn a decision once again as Younis survives after being adjudged leg before off Dilruwan. Pak 111-3.
Younis sweeps Herath along the ground to square leg to bring up the 50-run partnership with Misbah. Pak 109-3
Younis races to his 29th Test half century with three consecutive boundaries off Dilruwan. Pak 96-3.
Productive over for Pakistan with Younis nearly getting a boundary with a reverse sweep offf Dilruwan. Pak 79-3.
Misbah is finally tired of ducking bouncers, rocking back and hooking Prasad to the square leg fence.
Misbah survives a vociferous appeal for leg before off Mathews in the third over after lunch with Sri Lanka being unsuccessful with the decision review. Pak 59-3.
Sri Lanka’s seamer Dhammika Prasad removed both openers cheaply as Pakistan made a shaky start after electing to bat in the first Test in Galle on Wednesday.
Pakistan were reduced to 19-2 by the sixth over before a partial recovery helped the tourists move to 59-3 by lunch on the opening day.
Prasad, working up a tidy pace on a pitch that afforded bounce and movement, bowled Ahmed Shehzad off the inside edge with his third delivery after being hit for a boundary off the first.
The seamer then trapped Khurram Manzoor leg-before in his third over, but Azhar Ali and Younis Khan settled in to put on 37 as the wicket eased out under the mild sun.
Ali, who hit five boundaries in his fluent 30, failed to last till lunch as he fell to a good delivery from left-arm spinner Rangana Herath, which turned and clipped the off-stump.
At the break, Younis Khan was unbeaten on 21 and skipper Misbah-ul Haq had yet to score.
The start was delayed by 30 minutes due to a wet outfield caused by overnight rain. Bad weather has been forecast on all five days of the Test.
Both teams went in with two spinners - Saeed Ajmal and Abdur Rehman for Pakistan, and Herath and Dilruwan Perera for the hosts - hoping the grassless pitch provides some turn later in the match.
Pakistan are 59-3 in 26 overs at lunch with Younis unbeaten on 21 and Misbah yet to open his account.
Pakistan are successful with a decision review as Younis is adjudged caught behind but replays suggested it had clipped his pad. Pak 58-3.
Herath produces a peach of a delivery to clip the bail of Azhar with players going up for a caught behind before the player walked. Pak 56-3 in 22 overs.
Azhar Ali b Herath 30 (69b 5x4 0x6)
Azhar sweeps Dilruwan to the square leg boundary as Pakistan continue to rebuild their innings. Pak 55-2.
Dilruwan opens with a maiden as Sri Lanka employ spin from both ends with Herath getting turn from his first over. Pak 47-2.
Younis hits his first boundary steering Mathews to third man. Pak 43-2.
Azhar slams his fourth boundary crunching Prasad through the covers as drinks are taken. Pak 34-2 in 12 overs.
First bowling change as Mathews brings himself on replacing Eranga.
Azhar drives Prasad through extra cover for another boundary. Pak 28-2.
Prasad strikes again trapping Manzoor leg before with umpire Gould raising his finger after some deliberation. Pak 19-2 in 5.4 overs.
Khurram Manzoor lbw b Prasad 3 (19b 0x4 0x6)
Azhar opens his account with a boundary off Prasad via an outside edge to the vacant third man region followed by a classic cover drive to the fence. Pak 12-1.
Shehzad hits the first boundary of the match via an inside edge off Prasad who strikes two balls later to clatter the batsman's stumps with a delivery which nipped back. Pak 4-1 in 1.3 overs.
Ahmed Shehzad b Prasad 4 (3b 1x4 0x6)
Eranga begins with a maiden while Manzoor survives a confident shout for leg before.
Manzoor and Shehzad open for Pakistan while Eranga has been handed the new ball.
Retiring great Mahela Jayawardene has been given a guard of honour by two groups of children as he leads out Sri Lanka onto the field in his farewell Test series.
Pakistan have won the toss and decided to bat in the first Test against Sri Lanka at Galle International Cricket Stadium on Wednesday.
The toss was delayed because of a wet outfield.
Sri Lanka: Upul Tharanga, Kaushal Silva, Kumar Sangakkara, Mahela Jayawardene, Angelo Mathews, Kithruwan Vithanage, Niroshan Dickwella, Kusal Perera, Dhammika Prasad, Rangana Herath, Shaminda Eranga
Pakistan: Khurram Manzoor, Ahmed Shehzad, Azhar Ali, Younis Khan, Misbah-ul-Haq, Asad Shafiq, Sarfraz Ahmed, Abdur Rehman, Mohammad Talha, Saeed Ajmal, Junaid Khan
Rusty Pakistan and overworked Sri Lanka are set for an enthralling contest when they open a two-Test series in Galle on Wednesday, the last for the retiring Mahela Jayawardene.
The former Sri Lankan captain, whose elegant batting has seen him rise to sixth place in the all-time scorers' list with 11,671 runs in 147 Tests, is due to quit the longer format after the series.
But rival captains Misbah-ul Haq of Pakistan and Angelo Mathews of Sri Lanka will look to put aside the emotions of a farewell series as they find themselves battling contrasting worries.
While Pakistan may be under-prepared for their first Test series since January, Mathews said his team were "drained mentally and physically" due to a surfeit of international cricket.
Sri Lanka have been on the road since the start of the year, touring the United Arab Emirates, Bangladesh and England for Test and limited-overs cricket before last month's home series against South Africa.
Mathews rued the absence of a cooling-off period as he announced on Tuesday that seamer Suranga Lakmal would miss the series due to an ankle injury sustained against South Africa.
"Pakistan have had a good rest whereas we have been playing continuous cricket," the Sri Lankan captain said. "It's always good to get some rest to refresh your minds and bodies.
"That is the challenge we are facing as players. When you are playing constantly, you get drained mentally and physically. But the challenge for us is to try and be consistent.
"It works both ways. They (Pakistan) can be a bit rusty, but you never know. They are very unpredictable. They come out all guns blazing. They are a very formidable team when it comes to Tests."
Pakistan fought back to play out a 1-1 draw in their last Test series against Sri Lanka in the UAE in January, but have not won a series since beating England in 2012.
Misbah said his team were determined to win their first series in Sri Lanka since 2006.
"We have tried our best to get ready for this," the Pakistan captain said. "We had a good training camp before we came here. We worked hard on our fitness. Everybody is excited about the series.
"We know what to expect in Sri Lanka, who are a very strong side at home," he said. "So you need to play hard, disciplined cricket to come good against them."
Misbah said his team would target the retiring Jayawardene in the two matches since he could be the danger man for Sri Lanka.
"He is one of the best batsmen in the world. We don't want him to score runs, because if he gets runs it will be difficult for us to raise our game," he said.
"We will be really focusing on that and try our best to get him out early."