Pakistan's Azhar Ali defiantly scored his fourth Test hundred but hosts Sri Lanka still scented victory in the third and final Test with the tourists leading by 188 in their second innings at the end of the fourth day on Wednesday.
Asad Shafiq, who shared a fifth wicket partnership of 100 with Azhar at the Pallekele Stadium, was unbeaten on 55 off 134 balls, having hit five fours, with Adnan Akmal on nought to leave Pakistan on 299 for eight wickets at the close.
Akmal, who suffered a hairline fracture on his left ring finger on the opening day of the final Test, came in to bat at the fall of the eighth wicket and held out for the last 13 minutes to see Pakistan through to the close.
After being rewarded with only three wickets in the first two sessions, Sri Lanka, who lead the three-match series 1-0, picked four wickets in the final session as Pakistan battled to save the Test match and the series.
The second new ball taken after 80 overs produced two wickets for Dilhara Fernando who had Azhar playing a tired shot to be caught behind by Prasanna Jayawardene for a well compiled 136 off 284 balls (13 fours).
Fernando followed that up with the wicket of Mohammad Sami, trapped lbw for three, which brought him his 100th Test wicket and made him the fifth Sri Lanka bowler to achieve the feat.
Herath then turned on the heat by snapping up the wickets of Umar Gul (0) and Saeed Ajmal (5), both lbw victims, as Pakistan slid from a promising position of 276-4 to 299-8.
Pakistan lost two crucial wickets in the second session to reach 210 for four at tea. Herath removed Younus Khan (19) and skipper Misbah-ul-Haq (five) to put Sri Lanka on top.
Dropped by wicketkeeper Prasanna Jayawardene off Angelo Mathews when he was on 12, Younus could not make the most of the reprieve and edged Herath to Tharanga Paranavitana at silly point to give the bowler his 150th test wicket.
Herath returned to toss one up to Misbah whose attempted push ended in a catch to Mahela Jayawardene at slip.
Earlier, Mohammad Hafeez (52) and Azhar shared a second wicket stand of 94 runs as Pakistan bravely fought back.
Having conceded a 111 run first-innings lead, the overnight pair of Hafeez and Azhar looked like they would bat through the morning session having survived some testing bowling by Sri Lanka's seamers, especially Nuwan Kulasekara who had no luck.
They batted without any discomfort and were about to wipe out the deficit when Fernando gave Sri Lanka the breakthrough they had been seeking since play began under bright sunshine.
Hafeez, who completed a half-century off 93 balls, chased a wide delivery 10 minutes before the lunch break and presented a thick edge to lone slip fielder Paranavitana.
Image: Azhar Ali celebrates after registering his century.
Photograph: Buddhika Weerasinghe/Getty Images